From ae14814f108bb85ba28cb05da23205889b8c80f3 Mon Sep 17 00:00:00 2001 From: atm-quentin Date: Wed, 22 Jan 2020 15:27:50 +0100 Subject: [PATCH 1/5] NEW visu FROM day TO day in permonth view --- htdocs/core/lib/date.lib.php | 64 +++ htdocs/projet/activity/permonth.php | 656 ++++++++++++++++++++++++++++ 2 files changed, 720 insertions(+) create mode 100644 htdocs/projet/activity/permonth.php diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php index 8fb32bb2f37..2694747f52d 100644 --- a/htdocs/core/lib/date.lib.php +++ b/htdocs/core/lib/date.lib.php @@ -961,3 +961,67 @@ function monthArray($outputlangs, $short = 0) return $montharray; } +/** + * Return array of week numbers. + + * + * @param int $month Month number + * @param int $year Year number + * @return array Week numbers + */ + +function getWeekNumbersOfMonth($month, $year) { + $nb_days = cal_days_in_month(CAL_GREGORIAN,$month, $year); + $TWeek = array(); + for($day = 1; $day < $nb_days; $day++) { + $week_number = getWeekNumber($day, $month, $year); + $TWeek[$week_number] = $week_number; + } + return $TWeek; +} +/** + * Return array of first day of weeks. + + * + * @param array $TWeek array of week numbers + * @param int $year Year number + * @return array First day of week + */ +function getFirstDayOfEachWeek($TWeek, $year) { + $TFirstDayOfWeek = array(); + foreach($TWeek as $weekNb) { + if(in_array('01',$TWeek) && in_array('52',$TWeek) && $weekNb == '01') $year++;//Si on a la 1re semaine et la semaine 52 c'est qu'on change d'année + $TFirstDayOfWeek[$weekNb] = date('d',strtotime($year.'W'.$weekNb)); + } + return $TFirstDayOfWeek; +} +/** + * Return array of last day of weeks. + + * + * @param array $TWeek array of week numbers + * @param int $year Year number + * @return array Last day of week + */ +function getLastDayOfEachWeek($TWeek, $year) { + $TLastDayOfWeek = array(); + foreach($TWeek as $weekNb) { + $TLastDayOfWeek[$weekNb] = date('d',strtotime($year.'W'.$weekNb.'+6 days')); + } + return $TLastDayOfWeek; +} +/** + * Return week number. + + * + * @param int $day Day number + * @param int $month Month number + * @param int $year Year number + * @return int Week number + */ + +function getWeekNumber($day, $month, $year) { + $date = new DateTime($year.'-'.$month.'-'.$day); + $week = $date->format("W"); + return $week; +} diff --git a/htdocs/projet/activity/permonth.php b/htdocs/projet/activity/permonth.php new file mode 100644 index 00000000000..e35a47551b1 --- /dev/null +++ b/htdocs/projet/activity/permonth.php @@ -0,0 +1,656 @@ + + * Copyright (C) 2004-2015 Laurent Destailleur + * Copyright (C) 2005-2010 Regis Houssin + * Copyright (C) 2010 François Legastelois + * + * 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 . + */ + +/** + * \file htdocs/projet/activity/permonth.php + * \ingroup projet + * \brief List activities of tasks (per week entry) + */ + +require "../../main.inc.php"; +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'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; +require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; + +// Load translation files required by the page +$langs->loadLangs(array('projects','users','companies')); +$hookmanager->initHooks(array('timesheetpermonthcard')); + +$action=GETPOST('action','aZ09'); +$mode=GETPOST("mode",'alpha'); +$id=GETPOST('id','int'); +$taskid=GETPOST('taskid','int'); + +$mine=0; +if ($mode == 'mine') $mine=1; + +$projectid=''; +$projectid=isset($_GET["id"])?$_GET["id"]:$_POST["projectid"]; + +// Security check +$socid=0; +// For external user, no check is done on company because readability is managed by public status of project and assignement. +// if ($user->societe_id > 0) $socid=$user->societe_id; +$result = restrictedArea($user, 'projet', $projectid); + +$now=dol_now(); +$nowtmp=dol_getdate($now); +$nowday=$nowtmp['mday']; +$nowmonth=$nowtmp['mon']; +$nowyear=$nowtmp['year']; + +$year=GETPOST('reyear')?GETPOST('reyear','int'):(GETPOST("year")?GETPOST("year","int"):date("Y")); +$month=GETPOST('remonth')?GETPOST('remonth','int'):(GETPOST("month")?GETPOST("month","int"):date("m")); +$day=GETPOST('reday')?GETPOST('reday','int'):(GETPOST("day")?GETPOST("day","int"):date("d")); +$day = (int) $day; +$week=GETPOST("week","int")?GETPOST("week","int"):date("W"); + +$search_categ=GETPOST("search_categ",'alpha'); +$search_usertoprocessid=GETPOST('search_usertoprocessid', 'int'); +$search_task_ref=GETPOST('search_task_ref', 'alpha'); +$search_task_label=GETPOST('search_task_label', 'alpha'); +$search_project_ref=GETPOST('search_project_ref', 'alpha'); +$search_thirdparty=GETPOST('search_thirdparty', 'alpha'); +$search_declared_progress=GETPOST('search_declared_progress', 'alpha'); + +$startdayarray=dol_get_prev_month($month, $year); + +$prev = $startdayarray; +$prev_year = $prev['year']; +$prev_month = $prev['month']; +$prev_day = 1; + +$next = dol_get_next_month($month, $year); +$next_year = $next['year']; +$next_month = $next['month']; +$next_day = 1; +$TWeek = getWeekNumbersOfMonth($month, $year); +$firstdaytoshow = dol_mktime(0,0,0,$month,1,$year); +$TFirstDays = getFirstDayOfEachWeek($TWeek, $year); +$TFirstDays[reset($TWeek)] = '01'; //first day of month +$TLastDays = getLastDayOfEachWeek($TWeek, $year); +$TLastDays[end($TWeek)] = date("t", strtotime($year.'-'.$month.'-'.$day)); //last day of month +if (empty($search_usertoprocessid) || $search_usertoprocessid == $user->id) +{ + $usertoprocess=$user; + $search_usertoprocessid=$usertoprocess->id; +} +elseif ($search_usertoprocessid > 0) +{ + $usertoprocess=new User($db); + $usertoprocess->fetch($search_usertoprocessid); + $search_usertoprocessid=$usertoprocess->id; +} +else +{ + $usertoprocess=new User($db); +} + +$object=new Task($db); + + +/* + * Actions + */ +$parameters = array('id' => $id, 'taskid' => $taskid, 'projectid' => $projectid, 'TWeek' => $TWeek, 'TFirstDays' => $TFirstDays, 'TLastDays' => $TLastDays); +$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + +// Purge criteria +if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers +{ + $action = ''; + $search_categ=''; + $search_usertoprocessid = $user->id; + $search_task_ref = ''; + $search_task_label = ''; + $search_project_ref = ''; + $search_thirdparty = ''; + $search_declared_progress = ''; +} +if (GETPOST("button_search_x",'alpha') || GETPOST("button_search.x",'alpha') || GETPOST("button_search",'alpha')) +{ + $action = ''; +} + +if (GETPOST('submitdateselect')) +{ + $daytoparse = dol_mktime(0, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); + + $action = ''; +} +if ($action == 'addtime' && $user->rights->projet->lire && GETPOST('assigntask')) +{ + $action = 'assigntask'; + + if ($taskid > 0) + { + $result = $object->fetch($taskid, $ref); + if ($result < 0) $error++; + } + else + { + setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("Task")), '', 'errors'); + $error++; + } + if (! GETPOST('type')) + { + setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), '', 'errors'); + $error++; + } + + if (! $error) + { + $idfortaskuser=$usertoprocess->id; + $result = $object->add_contact($idfortaskuser, GETPOST("type"), 'internal'); + + if ($result >= 0 || $result == -2) // Contact add ok or already contact of task + { + // Test if we are already contact of the project (should be rare but sometimes we can add as task contact without being contact of project, like when admin user has been removed from contact of project) + $sql='SELECT ec.rowid FROM '.MAIN_DB_PREFIX.'element_contact as ec, '.MAIN_DB_PREFIX.'c_type_contact as tc WHERE tc.rowid = ec.fk_c_type_contact'; + $sql.=' AND ec.fk_socpeople = '.$idfortaskuser." AND ec.element_id = '.$object->fk_project.' AND tc.element = 'project' AND source = 'internal'"; + $resql=$db->query($sql); + if ($resql) + { + $obj=$db->fetch_object($resql); + if (! $obj) // User is not already linked to project, so we will create link to first type + { + $project = new Project($db); + $project->fetch($object->fk_project); + // Get type + $listofprojcontact=$project->liste_type_contact('internal'); + + if (count($listofprojcontact)) + { + $typeforprojectcontact=reset(array_keys($listofprojcontact)); + $result = $project->add_contact($idfortaskuser, $typeforprojectcontact, 'internal'); + } + } + } + else + { + dol_print_error($db); + } + } + } + + if ($result < 0) + { + $error++; + if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $langs->load("errors"); + setEventMessages($langs->trans("ErrorTaskAlreadyAssigned"), null, 'warnings'); + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + + if (! $error) + { + setEventMessages("TaskAssignedToEnterTime", null); + $taskid=0; + } + + $action=''; +} + +if ($action == 'addtime' && $user->rights->projet->lire) +{ + $timetoadd=$_POST['task']; + if (empty($timetoadd)) + { + setEventMessages($langs->trans("ErrorTimeSpentIsEmpty"), null, 'errors'); + } + else + { + + foreach($timetoadd as $taskid => $value) // Loop on each task + { + $updateoftaskdone=0; + foreach($value as $key => $val) // Loop on each day + { + $amountoadd=$timetoadd[$taskid][$key]; + if (! empty($amountoadd)) + { + $tmpduration=explode(':',$amountoadd); + $newduration=0; + if (! empty($tmpduration[0])) $newduration+=($tmpduration[0] * 3600); + if (! empty($tmpduration[1])) $newduration+=($tmpduration[1] * 60); + if (! empty($tmpduration[2])) $newduration+=($tmpduration[2]); + + if ($newduration > 0) + { + $object->fetch($taskid); + $object->progress = GETPOST($taskid . 'progress', 'int'); + $object->timespent_duration = $newduration; + $object->timespent_fk_user = $usertoprocess->id; + $object->timespent_date = dol_time_plus_duree($firstdaytoshow, $key, 'd'); + $object->timespent_datehour = $object->timespent_date; + + $result=$object->addTimeSpent($user); + if ($result < 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + $error++; + break; + } + + $updateoftaskdone++; + } + } + } + + if (! $updateoftaskdone) // Check to update progress if no update were done on task. + { + $object->fetch($taskid); + //var_dump($object->progress);var_dump(GETPOST($taskid . 'progress', 'int')); exit; + if ($object->progress != GETPOST($taskid . 'progress', 'int')) + { + $object->progress = GETPOST($taskid . 'progress', 'int'); + $result=$object->update($user); + if ($result < 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + $error++; + break; + } + } + } + } + + if (! $error) + { + setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); + + $param=''; + $param.=($mode?'&mode='.$mode:''); + $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_usertoprocessid > 0?'&search_usertoprocessid='.$search_usertoprocessid:''); + $param.=($search_thirdparty?'&search_thirdparty='.$search_thirdparty:''); + $param.=($search_declared_progress?'&search_declared_progress='.$search_declared_progress:''); + $param.=($search_task_ref?'&search_task_ref='.$search_task_ref:''); + $param.=($search_task_label?'&search_task_label='.$search_task_label:''); + + // Redirect to avoid submit twice on back + header('Location: '.$_SERVER["PHP_SELF"].'?'.$param); + exit; + } + } +} + + + +/* + * View + */ + +$form=new Form($db); +$formother=new FormOther($db); +$formcompany=new FormCompany($db); +$formproject=new FormProjets($db); +$projectstatic=new Project($db); +$project = new Project($db); +$taskstatic = new Task($db); +$thirdpartystatic = new Societe($db); +$holiday = new Holiday($db); + +$title=$langs->trans("TimeSpent"); + +$projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertoprocess,(empty($usertoprocess->id)?2:0),1); // Return all project i have permission on (assigned to me+public). I want my tasks and some of my task may be on a public projet that is not my project +//var_dump($projectsListId); +if ($id) +{ + $project->fetch($id); + $project->fetch_thirdparty(); +} + +$onlyopenedproject=1; // or -1 +$morewherefilter=''; + +if ($search_project_ref) $morewherefilter.=natural_search(array("p.ref", "p.title"), $search_project_ref); +if ($search_task_ref) $morewherefilter.=natural_search("t.ref", $search_task_ref); +if ($search_task_label) $morewherefilter.=natural_search(array("t.ref", "t.label"), $search_task_label); +if ($search_thirdparty) $morewherefilter.=natural_search("s.nom", $search_thirdparty); +if ($search_declared_progress) $morewherefilter.=natural_search("t.progress", $search_declared_progress, 1); + +$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 tasks of open 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 without any 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 tasks of open 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); +$tasksrole=$taskstatic->getUserRolesForProjectsOrTasks(0, $usertoprocess, ($project->id?$project->id:0), 0, $onlyopenedproject); +//var_dump($tasksarray); +//var_dump($projectsrole); +//var_dump($taskrole); + + +llxHeader("",$title,"",'','','',array('/core/js/timesheet.js')); + +//print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num, '', 'title_project'); + +$param=''; +$param.=($mode?'&mode='.$mode:''); +$param.=($search_project_ref?'&search_project_ref='.$search_project_ref:''); +$param.=($search_usertoprocessid > 0?'&search_usertoprocessid='.$search_usertoprocessid:''); +$param.=($search_thirdparty?'&search_thirdparty='.$search_thirdparty:''); +$param.=($search_task_ref?'&search_task_ref='.$search_task_ref:''); +$param.=($search_task_label?'&search_task_label='.$search_task_label:''); + +// Show navigation bar +$nav =''.img_previous($langs->trans("Previous"))."\n"; +$nav.=" ".dol_print_date(dol_mktime(0,0,0,$month,1,$year),"%Y").", ".$langs->trans(date('F', mktime(0, 0, 0, $month, 10)))." \n"; +$nav.=''.img_next($langs->trans("Next"))."\n"; +$nav.="   (".$langs->trans("Today").")"; +$nav.='
'.$form->select_date(-1,'',0,0,2,"addtime",1,0,1).' '; +$nav.=' '; + +$picto='calendarweek'; + +print '
'; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; + +$head=project_timesheet_prepare_head($mode, $usertoprocess); +dol_fiche_head($head, 'inputpermonth', $langs->trans('TimeSpent'), -1, 'task'); + +// Show description of content +print '
'; +if ($mine || ($usertoprocess->id == $user->id)) print $langs->trans("MyTasksDesc").'.'.($onlyopenedproject?' '.$langs->trans("OnlyOpenedProject"):'').'
'; +else +{ + if (empty($usertoprocess->id) || $usertoprocess->id < 0) + { + if ($user->rights->projet->all->lire && ! $socid) print $langs->trans("ProjectsDesc").'.'.($onlyopenedproject?' '.$langs->trans("OnlyOpenedProject"):'').'
'; + else print $langs->trans("ProjectsPublicTaskDesc").'.'.($onlyopenedproject?' '.$langs->trans("OnlyOpenedProject"):'').'
'; + } +} +if ($mine || ($usertoprocess->id == $user->id)) +{ + print $langs->trans("OnlyYourTaskAreVisible").'
'; +} +else +{ + print $langs->trans("AllTaskVisibleButEditIfYouAreAssigned").'
'; +} +print '
'; + +dol_fiche_end(); + +print '
'.$nav.'
'; // We move this before the assign to components so, the default submit button is not the assign to. + +print '
'; +$titleassigntask = $langs->transnoentities("AssignTaskToMe"); +if ($usertoprocess->id != $user->id) $titleassigntask = $langs->transnoentities("AssignTaskToUser", $usertoprocess->getFullName($langs)); +print '
'; +$formproject->selectTasks($socid?$socid:-1, $taskid, 'taskid', 32, 0, 1, 1); +print '
'; +print ' '; +print $formcompany->selectTypeContact($object, '', 'type','internal','rowid', 0, 'maxwidth150onsmartphone'); +print ''; +print '
'; + +print '
'; + + +$moreforfilter=''; + +// Filter on categories +/* +if (! empty($conf->categorie->enabled)) +{ + require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; + $moreforfilter.='
'; + $moreforfilter.=$langs->trans('ProjectCategories'). ': '; + $moreforfilter.=$formother->select_categories('project', $search_categ, 'search_categ', 1, 1, 'maxwidth300'); + $moreforfilter.='
'; +}*/ + +// If the user can view user other than himself +$moreforfilter.='
'; +$moreforfilter.='
'.$langs->trans('User'). '
'; +$includeonly='hierachyme'; +if (empty($user->rights->user->user->lire)) $includeonly=array($user->id); +$moreforfilter.=$form->select_dolusers($search_usertoprocessid?$search_usertoprocessid:$usertoprocess->id, 'search_usertoprocessid', $user->rights->user->user->lire?0:0, null, 0, $includeonly, null, 0, 0, 0, '', 0, '', 'maxwidth200'); +$moreforfilter.='
'; + +if (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)) +{ + $moreforfilter.='
'; + $moreforfilter.='
'.$langs->trans('Project'). '
'; + $moreforfilter.=''; + $moreforfilter.='
'; + + $moreforfilter.='
'; + $moreforfilter.='
'.$langs->trans('ThirdParty'). '
'; + $moreforfilter.=''; + $moreforfilter.='
'; +} + +if (! empty($moreforfilter)) +{ + print '
'; + print $moreforfilter; + $parameters=array(); + $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + print '
'; +} + +print '
'; + +print ''."\n"; + +print ''; +if (! empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)) print ''; +if (! empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)) print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +for ($idw=0;$idw'; +} +// Action column +print ''; +print "\n"; + +print ''; +if (! empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)) print ''; +if (! empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)) print ''; +print ''; +print ''; +print ''; +/*print ''; + if ($usertoprocess->id == $user->id) print ''; + else print '';*/ +print ''; +print ''; + +foreach ($TWeek as $week_number) +{ + print ''; +} +print ''; +print "\n"; + +$colspan=5; + +// By default, we can edit only tasks we are assigned to +$restrictviewformytask=(empty($conf->global->PROJECT_TIME_SHOW_TASK_NOT_ASSIGNED)?1:0); + +if (count($tasksarray) > 0) +{ + //var_dump($tasksarray); // contains only selected tasks + //var_dump($tasksarraywithoutfilter); // contains all tasks (if there is a filter, not defined if no filter) + //var_dump($tasksrole); + + $j=0; + $level=0; + $totalforvisibletasks = projectLinesPerMonth($j, $firstdaytoshow, $usertoprocess, 0, $tasksarray, $level, $projectsrole, $tasksrole, $mine, $restrictviewformytask, $isavailable, 0, $TWeek); + //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); + $totalforeachweek=array(); + foreach($listofdistinctprojectid as $tmpprojectid) + { + $projectstatic->id=$tmpprojectid; + $projectstatic->loadTimeSpentMonth($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 + foreach($TWeek as $weekNb) + { + $totalforeachweek[$weekNb]+=$projectstatic->monthWorkLoad[$weekNb]; + } + } + + //var_dump($totalforeachday); + //var_dump($totalforvisibletasks); + + // Is there a diff between selected/filtered tasks and all tasks ? + $isdiff = 0; + if (count($totalforeachweek)) + { + foreach($TWeek as $weekNb) + { + + $timeonothertasks=($totalforeachweek[$weekNb] - $totalforvisibletasks[$weekNb]); + if ($timeonothertasks) + { + $isdiff=1; + break; + } + } + } + + // 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 ($isdiff) + { + print ''; + print ''; + foreach ($TWeek as $weekNb) + { + print ''; + } + print ' '; + print ''; + } + + if ($conf->use_javascript_ajax) + { + print ' + '; + + foreach ($TWeek as $weekNb) + { + print ''; + } + print ' + '; + } +} +else +{ + print ''; +} +print "
'; +$searchpicto=$form->showFilterAndCheckAddButtons(0); +print $searchpicto; +print '
'.$langs->trans("Project").''.$langs->trans("ThirdParty").''.$langs->trans("Task").''.$langs->trans("PlannedWorkload").''.$langs->trans("ProgressDeclared").''.$langs->trans("TimeSpent").''.$langs->trans("TimeSpentByYou").''.$langs->trans("TimeSpentByUser").''.$langs->trans("TimeSpent").'
('.$langs->trans("Everybody").')
'.$langs->trans("TimeSpent").($usertoprocess->firstname?'
('.$usertoprocess->firstname.')':'').'
'.$langs->trans("Week").'
'.$week_number.'
('.$langs->trans('From').' '.$TFirstDays[$week_number].' '.$langs->trans('to').' '.$TLastDays[$week_number].')
'; + print $langs->trans("OtherFilteredTasks"); + print ''; + + $timeonothertasks=($totalforeachweek[$weekNb] - $totalforvisibletasks[$weekNb]); + if ($timeonothertasks) + { + print ''; + } + print '
'; + print $langs->trans("Total"); + print ' - '.$langs->trans("ExpectedWorkedHours").': '.price($usertoprocess->weeklyhours, 1, $langs, 0, 0).''; + print '
'. convertSecondToTime($totalforvisibletasks[$weekNb],'allhourmin').'
 
'.$langs->trans("NoAssignedTasks").'
"; +print '
'; + +print ''."\n"; + +print '
'; +print ''; +print '
'; + +print '
'."\n\n"; + +$modeinput='hours'; + +if ($conf->use_javascript_ajax) +{ + print "\n\n"; + print ''; +} + + +llxFooter(); + +$db->close(); From a001913751ac6a915412e51b2cd967f6e22ace0f Mon Sep 17 00:00:00 2001 From: atm-quentin Date: Thu, 21 Nov 2019 17:05:06 +0100 Subject: [PATCH 2/5] Debut modification saisie par mois NEW hook and data id NEW visu FROM day TO day in permonth view FIX --- htdocs/core/lib/date.lib.php | 9 +- htdocs/core/lib/project.lib.php | 277 +++++++++++++++++++++++++- htdocs/langs/en_US/projects.lang | 2 + htdocs/langs/fr_FR/projects.lang | 2 + htdocs/projet/activity/perday.php | 4 +- htdocs/projet/activity/perweek.php | 4 +- htdocs/projet/class/project.class.php | 66 ++++++ 7 files changed, 355 insertions(+), 9 deletions(-) diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php index 2694747f52d..b604ea831b1 100644 --- a/htdocs/core/lib/date.lib.php +++ b/htdocs/core/lib/date.lib.php @@ -963,7 +963,7 @@ function monthArray($outputlangs, $short = 0) } /** * Return array of week numbers. - + * * @param int $month Month number * @param int $year Year number @@ -981,7 +981,7 @@ function getWeekNumbersOfMonth($month, $year) { } /** * Return array of first day of weeks. - + * * @param array $TWeek array of week numbers * @param int $year Year number @@ -997,7 +997,7 @@ function getFirstDayOfEachWeek($TWeek, $year) { } /** * Return array of last day of weeks. - + * * @param array $TWeek array of week numbers * @param int $year Year number @@ -1012,14 +1012,13 @@ function getLastDayOfEachWeek($TWeek, $year) { } /** * Return week number. - + * * @param int $day Day number * @param int $month Month number * @param int $year Year number * @return int Week number */ - function getWeekNumber($day, $month, $year) { $date = new DateTime($year.'-'.$month.'-'.$day); $week = $date->format("W"); diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index 9842f5357b4..e2f08e7c092 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -263,6 +263,14 @@ function project_timesheet_prepare_head($mode, $fuser = null) $param .= ($mode ? '&mode='.$mode : ''); if (is_object($fuser) && $fuser->id > 0 && $fuser->id != $user->id) $param .= '&search_usertoprocessid='.$fuser->id; + if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERMONTH)) + { + $head[$h][0] = DOL_URL_ROOT."/projet/activity/permonth.php".($param?'?'.$param:''); + $head[$h][1] = $langs->trans("InputPerMonth"); + $head[$h][2] = 'inputpermonth'; + $h++; + } + if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERWEEK)) { $head[$h][0] = DOL_URL_ROOT."/projet/activity/perweek.php".($param ? '?'.$param : ''); @@ -1141,7 +1149,7 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr if ($oldprojectforbreak != -1) $oldprojectforbreak = $projectstatic->id; - print ''."\n"; + print ''."\n"; // User /* @@ -1520,7 +1528,7 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ if ($oldprojectforbreak != -1) $oldprojectforbreak = $projectstatic->id; - print ''."\n"; + print ''."\n"; // User /* @@ -1704,6 +1712,271 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ return $totalforeachday; } +/** + * Output a task line into a perday intput mode + * + * @param string $inc Line output identificator (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 task to show (0 to show all) + * @param Task[] $lines Array of lines (list of tasks but we will show only if we have a specific role on task) + * @param int $level Level (start to 0, then increased/decrease by recursive call) + * @param string $projectsrole Array of roles user has on project + * @param string $tasksrole Array of roles user has on task + * @param string $mine Show only task lines I am assigned 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 int $oldprojectforbreak Old project id of last project break + * @return array Array with time spent for $fuser for each day of week on tasks in $lines and substasks + */ +function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, &$isavailable, $oldprojectforbreak=0, $TWeek=array()) +{ + global $conf, $db, $user, $bc, $langs; + global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic; + + $numlines=count($lines); + + $lastprojectid=0; + $workloadforid=array(); + $totalforeachweek=array(); + $lineswithoutlevel0=array(); + + // Create a smaller array with sublevels only to be used later. This increase dramatically performances. + if ($parent == 0) // Always and only if at first level + { + for ($i = 0 ; $i < $numlines ; $i++) + { + if ($lines[$i]->fk_task_parent) $lineswithoutlevel0[]=$lines[$i]; + } + } + + //dol_syslog('projectLinesPerWeek inc='.$inc.' firstdaytoshow='.$firstdaytoshow.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0)); + + if (empty($oldprojectforbreak)) + { + $oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)?0:-1); // 0 = start break, -1 = never break + } + + for ($i = 0 ; $i < $numlines ; $i++) + { + if ($parent == 0) $level = 0; + + if ($lines[$i]->fk_task_parent == $parent) + { + // If we want all or we have a role on task, we show it + if (empty($mine) || ! empty($tasksrole[$lines[$i]->id])) + { + //dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project); + + // Break on a new project + if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) + { + $lastprojectid=$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])) + { + $projectstatic->loadTimeSpentMonth($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; + } + //var_dump($projectstatic->weekWorkLoadPerTask); + //var_dump('--- '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]); + + $projectstatic->id=$lines[$i]->fk_project; + $projectstatic->ref=$lines[$i]->projectref; + $projectstatic->title=$lines[$i]->projectlabel; + $projectstatic->public=$lines[$i]->public; + $projectstatic->thirdparty_name=$lines[$i]->thirdparty_name; + + $taskstatic->id=$lines[$i]->id; + $taskstatic->ref=($lines[$i]->ref?$lines[$i]->ref:$lines[$i]->id); + $taskstatic->label=$lines[$i]->label; + $taskstatic->date_start=$lines[$i]->date_start; + $taskstatic->date_end=$lines[$i]->date_end; + + $thirdpartystatic->id=$lines[$i]->thirdparty_id; + $thirdpartystatic->name=$lines[$i]->thirdparty_name; + $thirdpartystatic->email=$lines[$i]->thirdparty_email; + + if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id)) + { + print ''."\n"; + print ''; + print $projectstatic->getNomUrl(1,'',0,''.$langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]); + if ($thirdpartystatic->id > 0) print ' - '.$thirdpartystatic->getNomUrl(1); + if ($projectstatic->title) + { + print ' - '; + print $projectstatic->title; + } + print ''; + print ''; + } + + if ($oldprojectforbreak != -1) $oldprojectforbreak = $projectstatic->id; + print ''."\n"; + + // User + /* + print ''; + print $fuser->getNomUrl(1, 'withproject', 'time'); + print ''; + */ + + // Project + /*print ''; + if ($oldprojectforbreak == -1) print $projectstatic->getNomUrl(1,'',0,$langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]); + print "";*/ + + // Thirdparty + /*print ''; + if ($thirdpartystatic->id > 0) print $thirdpartystatic->getNomUrl(1, 'project'); + print '';*/ + + // Ref + print ''; + print ''; + for ($k = 0 ; $k < $level ; $k++) print "   "; + print $taskstatic->getNomUrl(1, 'withproject', 'time'); + // Label task + print '
'; + for ($k = 0 ; $k < $level ; $k++) print "   "; + //print $taskstatic->getNomUrl(0, 'withproject', 'time'); + print $taskstatic->label; + //print "
"; + //for ($k = 0 ; $k < $level ; $k++) print "   "; + //print get_date_range($lines[$i]->date_start,$lines[$i]->date_end,'',$langs,0); + print "\n"; + + // Planned Workload + print ''; + if ($lines[$i]->planned_workload) print convertSecondToTime($lines[$i]->planned_workload,'allhourmin'); + else print '--:--'; + print ''; + + // Progress declared % + print ''; + print $formother->select_percent($lines[$i]->progress, $lines[$i]->id . 'progress'); + print ''; + + // Time spent by everybody + print ''; + // $lines[$i]->duration is a denormalised field = summ of time spent by everybody for task. What we need is time consummed by user + if ($lines[$i]->duration) + { + print ''; + print convertSecondToTime($lines[$i]->duration,'allhourmin'); + print ''; + } + else print '--:--'; + print "\n"; + + // Time spent by user + print ''; + $tmptimespent=$taskstatic->getSummaryOfTimeSpent($fuser->id); + if ($tmptimespent['total_duration']) print convertSecondToTime($tmptimespent['total_duration'],'allhourmin'); + else print '--:--'; + print "\n"; + + $disabledproject=1;$disabledtask=1; + //print "x".$lines[$i]->fk_project; + //var_dump($lines[$i]); + //var_dump($projectsrole[$lines[$i]->fk_project]); + // If at least one role for project + if ($lines[$i]->public || ! empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer) + { + $disabledproject=0; + $disabledtask=0; + } + // If $restricteditformytask is on and I have no role on task, i disable edit + if ($restricteditformytask && empty($tasksrole[$lines[$i]->id])) + { + $disabledtask=1; + } + + //var_dump($projectstatic->weekWorkLoadPerTask); + //TODO + // Fields to show current time + $tableCell=''; $modeinput='hours'; + $TFirstDay = getFirstDayOfEachWeek($TWeek, date('Y',$firstdaytoshow)); + $TFirstDay[reset($TWeek)] = 1; + foreach($TFirstDay as &$fday) { + $fday--; + } + foreach ($TWeek as $weekNb) + { + + $weekWorkLoad = $projectstatic->monthWorkLoadPerTask[$weekNb][$lines[$i]->id]; + $totalforeachweek[$weekNb]+=$weekWorkLoad; + + $alreadyspent=''; + if ($weekWorkLoad > 0) $alreadyspent=convertSecondToTime($weekWorkLoad,'allhourmin'); + $alttitle=$langs->trans("AddHereTimeSpentForWeek",$weekNb); + + + $tableCell =''; + $placeholder=''; + if ($alreadyspent) + { + $tableCell.=''; + //$placeholder=' placeholder="00:00"'; + //$tableCell.='+'; + } + + $tableCell.=''; + $tableCell.=''; + print $tableCell; + } + + // Warning + print ''; + if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("UserIsNotContactOfProject")); + else if ($disabledtask) + { + $titleassigntask = $langs->trans("AssignTaskToMe"); + if ($fuser->id != $user->id) $titleassigntask = $langs->trans("AssignTaskToUser", '...'); + + print $form->textwithpicto('',$langs->trans("TaskIsNotAssignedToUser", $titleassigntask)); + } + print ''; + + print "\n"; + } + + // Call to show task with a lower level (task under the current task) + $inc++; + $level++; + if ($lines[$i]->id > 0) + { + //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level); + //var_dump($totalforeachday); + $ret = projectLinesPerMonth($inc, $firstdaytoshow, $fuser, $lines[$i]->id, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $isavailable, $oldprojectforbreak, $TWeek); + //var_dump('ret with parent='.$lines[$i]->id.' level='.$level); + //var_dump($ret); + foreach($ret as $key => $val) + { + $totalforeachweek[$key]+=$val; + } + //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level.' + subtasks'); + //var_dump($totalforeachday); + } + $level--; + } + else + { + //$level--; + } + } + + return $totalforeachweek; +} + /** * Search in task lines with a particular parent if there is a task for a particular user (in taskrole) diff --git a/htdocs/langs/en_US/projects.lang b/htdocs/langs/en_US/projects.lang index 0f9c1d8f1b3..14d0e9d2b19 100644 --- a/htdocs/langs/en_US/projects.lang +++ b/htdocs/langs/en_US/projects.lang @@ -69,6 +69,7 @@ NewTask=New task AddTask=Create task AddTimeSpent=Create time spent AddHereTimeSpentForDay=Add here time spent for this day/task +AddHereTimeSpentForWeek=Add here time spent for this week/task Activity=Activity Activities=Tasks/activities MyActivities=My tasks/activities @@ -187,6 +188,7 @@ ProjectMustBeValidatedFirst=Project must be validated first FirstAddRessourceToAllocateTime=Assign a user resource to task to allocate time InputPerDay=Input per day InputPerWeek=Input per week +InputPerMonth=Input per month InputDetail=Input detail TimeAlreadyRecorded=This is time spent already recorded for this task/day and user %s ProjectsWithThisUserAsContact=Projects with this user as contact diff --git a/htdocs/langs/fr_FR/projects.lang b/htdocs/langs/fr_FR/projects.lang index 388de918e05..e1de5b386a1 100644 --- a/htdocs/langs/fr_FR/projects.lang +++ b/htdocs/langs/fr_FR/projects.lang @@ -69,6 +69,7 @@ NewTask=Nouvelle tâche AddTask=Créer tâche AddTimeSpent=Saisir temps consommé AddHereTimeSpentForDay=Ajoutez ici le temps passé pour cette journée/tâche +AddHereTimeSpentForWeek=Ajoutez ici le temps passé pour cette semaine/tâche Activity=Activité Activities=Tâches/activités MyActivities=Mes tâches/activités @@ -187,6 +188,7 @@ ProjectMustBeValidatedFirst=Le projet doit être validé d'abord FirstAddRessourceToAllocateTime=Affecter un utilisateur pour saisir des temps InputPerDay=Saisie par jour InputPerWeek=Saisie par semaine +InputPerMonth=Saisie par mois InputDetail=Saisir le détail TimeAlreadyRecorded=C'est le temps passé déjà enregistré pour cette tâche/jour et pour l'utilisateur %s ProjectsWithThisUserAsContact=Projets avec cet utilisateur comme contact diff --git a/htdocs/projet/activity/perday.php b/htdocs/projet/activity/perday.php index 8215eec4258..9e056ba5029 100644 --- a/htdocs/projet/activity/perday.php +++ b/htdocs/projet/activity/perday.php @@ -146,7 +146,9 @@ $search_array_options_task = $extrafields->getOptionalsFromPost($object->table_e /* * Actions */ - +$parameters = array('id' => $id, 'taskid' => $taskid, 'projectid' => $projectid); +$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); // Purge criteria if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers { diff --git a/htdocs/projet/activity/perweek.php b/htdocs/projet/activity/perweek.php index 8b69fc6aa01..085b54b9bdb 100644 --- a/htdocs/projet/activity/perweek.php +++ b/htdocs/projet/activity/perweek.php @@ -162,7 +162,9 @@ $search_array_options_task = $extrafields->getOptionalsFromPost('projet_task', ' /* * Actions */ - +$parameters = array('id' => $id, 'taskid' => $taskid, 'projectid' => $projectid); +$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); // Purge criteria if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers { diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 54d13a51549..048ea819187 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -1797,6 +1797,72 @@ class Project extends CommonObject return -1; } } + /** + * 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 $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 loadTimeSpentMonth($datestart, $taskid=0, $userid=0) + { + $error=0; + + $this->monthWorkLoad=array(); + $this->monthWorkLoadPerTask=array(); + + if (empty($datestart)) dol_print_error('','Error datestart parameter is empty'); + + $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.= " 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(dol_time_plus_duree($datestart, 1, 'm') - 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) + { + $weekalreadyfound=array(); + + $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); + if(!empty($obj->task_date)) { + $date = explode('-',$obj->task_date); + $week_number = getWeekNumber($date[2], $date[1], $date[0]); + } + if (empty($weekalreadyfound[$week_number])) + { + $this->monthWorkLoad[$week_number] = $obj->task_duration; + $this->monthWorkLoadPerTask[$week_number][$obj->fk_task] = $obj->task_duration; + } + else + { + $this->monthWorkLoad[$week_number] += $obj->task_duration; + $this->monthWorkLoadPerTask[$week_number][$obj->fk_task] += $obj->task_duration; + } + $weekalreadyfound[$week_number]=1; + $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; + } + } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps From fee113bfb5bf928fa4630305490668fb28029b23 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Fri, 31 Jan 2020 10:26:33 +0000 Subject: [PATCH 3/5] Fixing style errors. --- htdocs/core/lib/date.lib.php | 20 +++++++----- htdocs/core/lib/project.lib.php | 23 +++++++------- htdocs/projet/activity/perday.php | 2 +- htdocs/projet/activity/permonth.php | 46 +++++++++++++-------------- htdocs/projet/activity/perweek.php | 2 +- htdocs/projet/class/project.class.php | 6 ++-- 6 files changed, 50 insertions(+), 49 deletions(-) diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php index b604ea831b1..43a28a4b05c 100644 --- a/htdocs/core/lib/date.lib.php +++ b/htdocs/core/lib/date.lib.php @@ -970,8 +970,9 @@ function monthArray($outputlangs, $short = 0) * @return array Week numbers */ -function getWeekNumbersOfMonth($month, $year) { - $nb_days = cal_days_in_month(CAL_GREGORIAN,$month, $year); +function getWeekNumbersOfMonth($month, $year) +{ + $nb_days = cal_days_in_month(CAL_GREGORIAN, $month, $year); $TWeek = array(); for($day = 1; $day < $nb_days; $day++) { $week_number = getWeekNumber($day, $month, $year); @@ -987,11 +988,12 @@ function getWeekNumbersOfMonth($month, $year) { * @param int $year Year number * @return array First day of week */ -function getFirstDayOfEachWeek($TWeek, $year) { +function getFirstDayOfEachWeek($TWeek, $year) +{ $TFirstDayOfWeek = array(); foreach($TWeek as $weekNb) { - if(in_array('01',$TWeek) && in_array('52',$TWeek) && $weekNb == '01') $year++;//Si on a la 1re semaine et la semaine 52 c'est qu'on change d'année - $TFirstDayOfWeek[$weekNb] = date('d',strtotime($year.'W'.$weekNb)); + if(in_array('01', $TWeek) && in_array('52', $TWeek) && $weekNb == '01') $year++;//Si on a la 1re semaine et la semaine 52 c'est qu'on change d'année + $TFirstDayOfWeek[$weekNb] = date('d', strtotime($year.'W'.$weekNb)); } return $TFirstDayOfWeek; } @@ -1003,10 +1005,11 @@ function getFirstDayOfEachWeek($TWeek, $year) { * @param int $year Year number * @return array Last day of week */ -function getLastDayOfEachWeek($TWeek, $year) { +function getLastDayOfEachWeek($TWeek, $year) +{ $TLastDayOfWeek = array(); foreach($TWeek as $weekNb) { - $TLastDayOfWeek[$weekNb] = date('d',strtotime($year.'W'.$weekNb.'+6 days')); + $TLastDayOfWeek[$weekNb] = date('d', strtotime($year.'W'.$weekNb.'+6 days')); } return $TLastDayOfWeek; } @@ -1019,7 +1022,8 @@ function getLastDayOfEachWeek($TWeek, $year) { * @param int $year Year number * @return int Week number */ -function getWeekNumber($day, $month, $year) { +function getWeekNumber($day, $month, $year) +{ $date = new DateTime($year.'-'.$month.'-'.$day); $week = $date->format("W"); return $week; diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index e2f08e7c092..d7275d3343a 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -1729,7 +1729,7 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ * @param int $oldprojectforbreak Old project id of last project break * @return array Array with time spent for $fuser for each day of week on tasks in $lines and substasks */ -function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, &$isavailable, $oldprojectforbreak=0, $TWeek=array()) +function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, &$isavailable, $oldprojectforbreak = 0, $TWeek = array()) { global $conf, $db, $user, $bc, $langs; global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic; @@ -1805,7 +1805,7 @@ function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, & { print ''."\n"; print ''; - print $projectstatic->getNomUrl(1,'',0,''.$langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]); + print $projectstatic->getNomUrl(1, '', 0, ''.$langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]); if ($thirdpartystatic->id > 0) print ' - '.$thirdpartystatic->getNomUrl(1); if ($projectstatic->title) { @@ -1853,7 +1853,7 @@ function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, & // Planned Workload print ''; - if ($lines[$i]->planned_workload) print convertSecondToTime($lines[$i]->planned_workload,'allhourmin'); + if ($lines[$i]->planned_workload) print convertSecondToTime($lines[$i]->planned_workload, 'allhourmin'); else print '--:--'; print ''; @@ -1868,7 +1868,7 @@ function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, & if ($lines[$i]->duration) { print ''; - print convertSecondToTime($lines[$i]->duration,'allhourmin'); + print convertSecondToTime($lines[$i]->duration, 'allhourmin'); print ''; } else print '--:--'; @@ -1877,7 +1877,7 @@ function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, & // Time spent by user print ''; $tmptimespent=$taskstatic->getSummaryOfTimeSpent($fuser->id); - if ($tmptimespent['total_duration']) print convertSecondToTime($tmptimespent['total_duration'],'allhourmin'); + if ($tmptimespent['total_duration']) print convertSecondToTime($tmptimespent['total_duration'], 'allhourmin'); else print '--:--'; print "\n"; @@ -1901,20 +1901,19 @@ function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, & //TODO // Fields to show current time $tableCell=''; $modeinput='hours'; - $TFirstDay = getFirstDayOfEachWeek($TWeek, date('Y',$firstdaytoshow)); + $TFirstDay = getFirstDayOfEachWeek($TWeek, date('Y', $firstdaytoshow)); $TFirstDay[reset($TWeek)] = 1; foreach($TFirstDay as &$fday) { $fday--; } foreach ($TWeek as $weekNb) { - $weekWorkLoad = $projectstatic->monthWorkLoadPerTask[$weekNb][$lines[$i]->id]; $totalforeachweek[$weekNb]+=$weekWorkLoad; $alreadyspent=''; - if ($weekWorkLoad > 0) $alreadyspent=convertSecondToTime($weekWorkLoad,'allhourmin'); - $alttitle=$langs->trans("AddHereTimeSpentForWeek",$weekNb); + if ($weekWorkLoad > 0) $alreadyspent=convertSecondToTime($weekWorkLoad, 'allhourmin'); + $alttitle=$langs->trans("AddHereTimeSpentForWeek", $weekNb); $tableCell =''; @@ -1936,13 +1935,13 @@ function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, & // Warning print ''; - if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("UserIsNotContactOfProject")); - else if ($disabledtask) + if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('', $langs->trans("UserIsNotContactOfProject")); + elseif ($disabledtask) { $titleassigntask = $langs->trans("AssignTaskToMe"); if ($fuser->id != $user->id) $titleassigntask = $langs->trans("AssignTaskToUser", '...'); - print $form->textwithpicto('',$langs->trans("TaskIsNotAssignedToUser", $titleassigntask)); + print $form->textwithpicto('', $langs->trans("TaskIsNotAssignedToUser", $titleassigntask)); } print ''; diff --git a/htdocs/projet/activity/perday.php b/htdocs/projet/activity/perday.php index 9e056ba5029..2489104eb34 100644 --- a/htdocs/projet/activity/perday.php +++ b/htdocs/projet/activity/perday.php @@ -147,7 +147,7 @@ $search_array_options_task = $extrafields->getOptionalsFromPost($object->table_e * Actions */ $parameters = array('id' => $id, 'taskid' => $taskid, 'projectid' => $projectid); -$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks +$reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); // Purge criteria if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers diff --git a/htdocs/projet/activity/permonth.php b/htdocs/projet/activity/permonth.php index e35a47551b1..93c1edb6757 100644 --- a/htdocs/projet/activity/permonth.php +++ b/htdocs/projet/activity/permonth.php @@ -38,10 +38,10 @@ require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; $langs->loadLangs(array('projects','users','companies')); $hookmanager->initHooks(array('timesheetpermonthcard')); -$action=GETPOST('action','aZ09'); -$mode=GETPOST("mode",'alpha'); -$id=GETPOST('id','int'); -$taskid=GETPOST('taskid','int'); +$action=GETPOST('action', 'aZ09'); +$mode=GETPOST("mode", 'alpha'); +$id=GETPOST('id', 'int'); +$taskid=GETPOST('taskid', 'int'); $mine=0; if ($mode == 'mine') $mine=1; @@ -61,13 +61,13 @@ $nowday=$nowtmp['mday']; $nowmonth=$nowtmp['mon']; $nowyear=$nowtmp['year']; -$year=GETPOST('reyear')?GETPOST('reyear','int'):(GETPOST("year")?GETPOST("year","int"):date("Y")); -$month=GETPOST('remonth')?GETPOST('remonth','int'):(GETPOST("month")?GETPOST("month","int"):date("m")); -$day=GETPOST('reday')?GETPOST('reday','int'):(GETPOST("day")?GETPOST("day","int"):date("d")); +$year=GETPOST('reyear')?GETPOST('reyear', 'int'):(GETPOST("year")?GETPOST("year", "int"):date("Y")); +$month=GETPOST('remonth')?GETPOST('remonth', 'int'):(GETPOST("month")?GETPOST("month", "int"):date("m")); +$day=GETPOST('reday')?GETPOST('reday', 'int'):(GETPOST("day")?GETPOST("day", "int"):date("d")); $day = (int) $day; -$week=GETPOST("week","int")?GETPOST("week","int"):date("W"); +$week=GETPOST("week", "int")?GETPOST("week", "int"):date("W"); -$search_categ=GETPOST("search_categ",'alpha'); +$search_categ=GETPOST("search_categ", 'alpha'); $search_usertoprocessid=GETPOST('search_usertoprocessid', 'int'); $search_task_ref=GETPOST('search_task_ref', 'alpha'); $search_task_label=GETPOST('search_task_label', 'alpha'); @@ -87,7 +87,7 @@ $next_year = $next['year']; $next_month = $next['month']; $next_day = 1; $TWeek = getWeekNumbersOfMonth($month, $year); -$firstdaytoshow = dol_mktime(0,0,0,$month,1,$year); +$firstdaytoshow = dol_mktime(0, 0, 0, $month, 1, $year); $TFirstDays = getFirstDayOfEachWeek($TWeek, $year); $TFirstDays[reset($TWeek)] = '01'; //first day of month $TLastDays = getLastDayOfEachWeek($TWeek, $year); @@ -115,11 +115,11 @@ $object=new Task($db); * Actions */ $parameters = array('id' => $id, 'taskid' => $taskid, 'projectid' => $projectid, 'TWeek' => $TWeek, 'TFirstDays' => $TFirstDays, 'TLastDays' => $TLastDays); -$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks +$reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); // Purge criteria -if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers +if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers { $action = ''; $search_categ=''; @@ -130,7 +130,7 @@ if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x', $search_thirdparty = ''; $search_declared_progress = ''; } -if (GETPOST("button_search_x",'alpha') || GETPOST("button_search.x",'alpha') || GETPOST("button_search",'alpha')) +if (GETPOST("button_search_x", 'alpha') || GETPOST("button_search.x", 'alpha') || GETPOST("button_search", 'alpha')) { $action = ''; } @@ -228,7 +228,6 @@ if ($action == 'addtime' && $user->rights->projet->lire) } else { - foreach($timetoadd as $taskid => $value) // Loop on each task { $updateoftaskdone=0; @@ -237,7 +236,7 @@ if ($action == 'addtime' && $user->rights->projet->lire) $amountoadd=$timetoadd[$taskid][$key]; if (! empty($amountoadd)) { - $tmpduration=explode(':',$amountoadd); + $tmpduration=explode(':', $amountoadd); $newduration=0; if (! empty($tmpduration[0])) $newduration+=($tmpduration[0] * 3600); if (! empty($tmpduration[1])) $newduration+=($tmpduration[1] * 60); @@ -324,7 +323,7 @@ $holiday = new Holiday($db); $title=$langs->trans("TimeSpent"); -$projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertoprocess,(empty($usertoprocess->id)?2:0),1); // Return all project i have permission on (assigned to me+public). I want my tasks and some of my task may be on a public projet that is not my project +$projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertoprocess, (empty($usertoprocess->id)?2:0), 1); // Return all project i have permission on (assigned to me+public). I want my tasks and some of my task may be on a public projet that is not my project //var_dump($projectsListId); if ($id) { @@ -353,7 +352,7 @@ $tasksrole=$taskstatic->getUserRolesForProjectsOrTasks(0, $usertoprocess, ($proj //var_dump($taskrole); -llxHeader("",$title,"",'','','',array('/core/js/timesheet.js')); +llxHeader("", $title, "", '', '', '', array('/core/js/timesheet.js')); //print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num, '', 'title_project'); @@ -367,10 +366,10 @@ $param.=($search_task_label?'&search_task_label='.$search_task_label:''); // Show navigation bar $nav =''.img_previous($langs->trans("Previous"))."\n"; -$nav.=" ".dol_print_date(dol_mktime(0,0,0,$month,1,$year),"%Y").", ".$langs->trans(date('F', mktime(0, 0, 0, $month, 10)))." \n"; +$nav.=" ".dol_print_date(dol_mktime(0, 0, 0, $month, 1, $year), "%Y").", ".$langs->trans(date('F', mktime(0, 0, 0, $month, 10)))." \n"; $nav.=''.img_next($langs->trans("Next"))."\n"; $nav.="   (".$langs->trans("Today").")"; -$nav.='
'.$form->select_date(-1,'',0,0,2,"addtime",1,0,1).' '; +$nav.='
'.$form->select_date(-1, '', 0, 0, 2, "addtime", 1, 0, 1).' '; $nav.=' '; $picto='calendarweek'; @@ -418,7 +417,7 @@ print '
'; $formproject->selectTasks($socid?$socid:-1, $taskid, 'taskid', 32, 0, 1, 1); print '
'; print ' '; -print $formcompany->selectTypeContact($object, '', 'type','internal','rowid', 0, 'maxwidth150onsmartphone'); +print $formcompany->selectTypeContact($object, '', 'type', 'internal', 'rowid', 0, 'maxwidth150onsmartphone'); print ''; print ''; @@ -464,7 +463,7 @@ if (! empty($moreforfilter)) print '
'; print $moreforfilter; $parameters=array(); - $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook + $reshook=$hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; print '
'; } @@ -559,7 +558,6 @@ if (count($tasksarray) > 0) { foreach($TWeek as $weekNb) { - $timeonothertasks=($totalforeachweek[$weekNb] - $totalforvisibletasks[$weekNb]); if ($timeonothertasks) { @@ -584,7 +582,7 @@ if (count($tasksarray) > 0) if ($timeonothertasks) { print ''; } print ''; @@ -603,7 +601,7 @@ if (count($tasksarray) > 0) foreach ($TWeek as $weekNb) { - print '
'. convertSecondToTime($totalforvisibletasks[$weekNb],'allhourmin').'
'; + print '
'. convertSecondToTime($totalforvisibletasks[$weekNb], 'allhourmin').'
'; } print '
 
'; diff --git a/htdocs/projet/activity/perweek.php b/htdocs/projet/activity/perweek.php index 085b54b9bdb..563b7ca19c9 100644 --- a/htdocs/projet/activity/perweek.php +++ b/htdocs/projet/activity/perweek.php @@ -163,7 +163,7 @@ $search_array_options_task = $extrafields->getOptionalsFromPost('projet_task', ' * Actions */ $parameters = array('id' => $id, 'taskid' => $taskid, 'projectid' => $projectid); -$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks +$reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); // Purge criteria if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 048ea819187..ce1c8fdaf17 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -1806,14 +1806,14 @@ class Project extends CommonObject * @param int $userid Time spent by a particular user * @return int <0 if OK, >0 if KO */ - public function loadTimeSpentMonth($datestart, $taskid=0, $userid=0) + public function loadTimeSpentMonth($datestart, $taskid = 0, $userid = 0) { $error=0; $this->monthWorkLoad=array(); $this->monthWorkLoadPerTask=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.task_datehour, ptt.fk_task"; $sql.= " FROM ".MAIN_DB_PREFIX."projet_task_time AS ptt, ".MAIN_DB_PREFIX."projet_task as pt"; @@ -1837,7 +1837,7 @@ class Project extends CommonObject { $obj=$this->db->fetch_object($resql); if(!empty($obj->task_date)) { - $date = explode('-',$obj->task_date); + $date = explode('-', $obj->task_date); $week_number = getWeekNumber($date[2], $date[1], $date[0]); } if (empty($weekalreadyfound[$week_number])) From 398e83d1cc6869f3c7e030f5393e22ad5a5a6437 Mon Sep 17 00:00:00 2001 From: atm-quentin Date: Fri, 31 Jan 2020 11:36:53 +0100 Subject: [PATCH 4/5] FIX for stickler --- htdocs/core/lib/date.lib.php | 1 - htdocs/core/lib/project.lib.php | 1 + htdocs/projet/activity/permonth.php | 3 ++- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php index 43a28a4b05c..e7043a1798a 100644 --- a/htdocs/core/lib/date.lib.php +++ b/htdocs/core/lib/date.lib.php @@ -969,7 +969,6 @@ function monthArray($outputlangs, $short = 0) * @param int $year Year number * @return array Week numbers */ - function getWeekNumbersOfMonth($month, $year) { $nb_days = cal_days_in_month(CAL_GREGORIAN, $month, $year); diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index d7275d3343a..9f55a431147 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -1727,6 +1727,7 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ * @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 int $oldprojectforbreak Old project id of last project break + * @param array $Tweek Array of week numbers * @return array Array with time spent for $fuser for each day of week on tasks in $lines and substasks */ function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, &$isavailable, $oldprojectforbreak = 0, $TWeek = array()) diff --git a/htdocs/projet/activity/permonth.php b/htdocs/projet/activity/permonth.php index 93c1edb6757..398f4c67199 100644 --- a/htdocs/projet/activity/permonth.php +++ b/htdocs/projet/activity/permonth.php @@ -480,7 +480,8 @@ print ''; print ''; print ''; print ''; -for ($idw=0;$idw'; } From 78baae1480ef5a645476c45b8ed948aa66962bed Mon Sep 17 00:00:00 2001 From: atm-quentin Date: Fri, 31 Jan 2020 11:51:40 +0100 Subject: [PATCH 5/5] Fix stickler v2 --- htdocs/core/lib/project.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index 9f55a431147..f39856f1bc1 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -1727,7 +1727,7 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ * @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 int $oldprojectforbreak Old project id of last project break - * @param array $Tweek Array of week numbers + * @param array $TWeek Array of week numbers * @return array Array with time spent for $fuser for each day of week on tasks in $lines and substasks */ function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, &$isavailable, $oldprojectforbreak = 0, $TWeek = array())