NEW: project time spent: conf to prevent recording time after X months

This commit is contained in:
Marc de Lima Lucio 2021-06-08 18:13:18 +02:00
parent 1468761073
commit 6733d278d8
5 changed files with 73 additions and 6 deletions

View File

@ -1076,6 +1076,13 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr
$oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT) ? 0 : -1); // 0 to start break , -1 no break
}
$restrictBefore = null;
if (! empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
$restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm');
}
//dol_syslog('projectLinesPerDay inc='.$inc.' preselectedday='.$preselectedday.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
for ($i = 0; $i < $numlines; $i++)
{
@ -1307,6 +1314,10 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr
$disabledtask = 1;
}
if ($restrictBefore && $preselectedday < $restrictBefore) {
$disabledtask = 1;
}
// Form to add new time
print '<td class="nowrap leftborder center">';
$tableCell = $form->selectDate($preselectedday, $lines[$i]->id, 1, 1, 2, "addtime", 0, 0, $disabledtask);
@ -1451,6 +1462,13 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$
$oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT) ? 0 : -1); // 0 = start break, -1 = never break
}
$restrictBefore = null;
if (! empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
$restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm');
}
for ($i = 0; $i < $numlines; $i++)
{
if ($parent == 0) $level = 0;
@ -1708,6 +1726,12 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$
$cssweekend = 'weekend';
}
$disabledtaskday = $disabledtask;
if (! $disabledtask && $restrictBefore && $tmpday < $restrictBefore) {
$disabledtaskday = 1;
}
$tableCell = '<td class="center hide'.$idw.($cssonholiday ? ' '.$cssonholiday : '').($cssweekend ? ' '.$cssweekend : '').'">';
//$tableCell .= 'idw='.$idw.' '.$conf->global->MAIN_START_WEEK.' '.$numstartworkingday.'-'.$numendworkingday;
$placeholder = '';
@ -1717,7 +1741,7 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$
//$placeholder=' placeholder="00:00"';
//$tableCell.='+';
}
$tableCell .= '<input type="text" alt="'.($disabledtask ? '' : $alttitle).'" title="'.($disabledtask ? '' : $alttitle).'" '.($disabledtask ? 'disabled' : $placeholder).' class="center smallpadd" size="2" id="timeadded['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="" cols="2" maxlength="5"';
$tableCell .= '<input type="text" alt="'.($disabledtaskday ? '' : $alttitle).'" title="'.($disabledtaskday ? '' : $alttitle).'" '.($disabledtaskday ? 'disabled' : $placeholder).' class="center smallpadd" 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 .= ' onkeyup="updateTotal('.$idw.',\''.$modeinput.'\')"';
$tableCell .= ' onblur="regexEvent(this,event,\''.$modeinput.'\'); updateTotal('.$idw.',\''.$modeinput.'\')" />';
@ -1812,6 +1836,13 @@ function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &
$oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT) ? 0 : -1); // 0 = start break, -1 = never break
}
$restrictBefore = null;
if (! empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
$restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm');
}
for ($i = 0; $i < $numlines; $i++)
{
if ($parent == 0) $level = 0;
@ -1954,10 +1985,11 @@ function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &
$tableCell = ''; $modeinput = 'hours';
$TFirstDay = getFirstDayOfEachWeek($TWeek, date('Y', $firstdaytoshow));
$TFirstDay[reset($TWeek)] = 1;
foreach ($TFirstDay as &$fday) {
$fday--;
}
foreach ($TWeek as $weekNb)
$firstdaytoshowarray = dol_getdate($firstdaytoshow);
$year = $firstdaytoshowarray['year'];
$month = $firstdaytoshowarray['mon'];
foreach ($TWeek as $weekIndex => $weekNb)
{
$weekWorkLoad = $projectstatic->monthWorkLoadPerTask[$weekNb][$lines[$i]->id];
$totalforeachweek[$weekNb] += $weekWorkLoad;
@ -1966,6 +1998,12 @@ function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &
if ($weekWorkLoad > 0) $alreadyspent = convertSecondToTime($weekWorkLoad, 'allhourmin');
$alttitle = $langs->trans("AddHereTimeSpentForWeek", $weekNb);
$disabledtaskweek = $disabledtask;
$firstdayofweek = dol_mktime(0, 0, 0, $month, $TFirstDay[$weekIndex], $year);
if (! $disabledtask && $restrictBefore && $firstdayofweek < $restrictBefore) {
$disabledtaskweek = 1;
}
$tableCell = '<td class="center hide weekend">';
$placeholder = '';
@ -1976,7 +2014,7 @@ function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &
//$tableCell.='+';
}
$tableCell .= '<input type="text" alt="'.($disabledtask ? '' : $alttitle).'" title="'.($disabledtask ? '' : $alttitle).'" '.($disabledtask ? 'disabled' : $placeholder).' class="center smallpadd" size="2" id="timeadded['.$inc.']['.((int) $weekNb).']" name="task['.$lines[$i]->id.']['.$TFirstDay[$weekNb].']" value="" cols="2" maxlength="5"';
$tableCell .= '<input type="text" alt="'.($disabledtaskweek ? '' : $alttitle).'" title="'.($disabledtaskweek ? '' : $alttitle).'" '.($disabledtaskweek ? 'disabled' : $placeholder).' class="center smallpadd" size="2" id="timeadded['.$inc.']['.((int) $weekNb).']" name="task['.$lines[$i]->id.']['.($TFirstDay[$weekNb] - 1).']" value="" cols="2" maxlength="5"';
$tableCell .= ' onkeypress="return regexEvent(this,event,\'timeChar\')"';
$tableCell .= ' onkeyup="updateTotal('.$weekNb.',\''.$modeinput.'\')"';
$tableCell .= ' onblur="regexEvent(this,event,\''.$modeinput.'\'); updateTotal('.$weekNb.',\''.$modeinput.'\')" />';

View File

@ -81,6 +81,7 @@ NumberOfBytes=Number of Bytes
SearchString=Search string
NotAvailableWhenAjaxDisabled=Not available when Ajax disabled
AllowToSelectProjectFromOtherCompany=On document of a third party, can choose a project linked to another third party
TimesheetPreventAfterFollowingMonths=Prevent recording time spent after the following number of months
JavascriptDisabled=JavaScript disabled
UsePreviewTabs=Use preview tabs
ShowPreview=Show preview

View File

@ -139,6 +139,7 @@ NoTasks=No tasks for this project
LinkedToAnotherCompany=Linked to other third party
TaskIsNotAssignedToUser=Task not assigned to user. Use button '<strong>%s</strong>' to assign task now.
ErrorTimeSpentIsEmpty=Time spent is empty
TimeRecordingRestrictedToNMonthsBack=Time recording is restricted to %s months back
ThisWillAlsoRemoveTasks=This action will also delete all tasks of project (<b>%s</b> tasks at the moment) and all inputs of time spent.
IfNeedToUseOtherObjectKeepEmpty=If some objects (invoice, order, ...), belonging to another third party, must be linked to the project to create, keep this empty to have the project being multi third parties.
CloneTasks=Clone tasks

View File

@ -242,6 +242,11 @@ elseif ($action == 'setdoc')
$projectToSelect = GETPOST('projectToSelect', 'alpha');
dolibarr_set_const($db, 'PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY', $projectToSelect, 'chaine', 0, '', $conf->entity); //Allow to disable this configuration if empty value
}
if (GETPOST('PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS'))
{
$timesheetFreezeDuration = GETPOST('timesheetFreezeDuration', 'alpha');
dolibarr_set_const($db, 'PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS', intval($timesheetFreezeDuration), 'chaine', 0, '', $conf->entity); //Allow to disable this configuration if empty value
}
}
@ -839,6 +844,16 @@ print '<input type="text" id="projectToSelect" name="projectToSelect" value="'.$
print $form->textwithpicto('', $langs->trans('AllowToLinkFromOtherCompany'));
print '<input type="submit" class="button" name="PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY" value="'.$langs->trans("Modify").'">';
print '</td>';
print '</tr>';
print '<tr class="oddeven">';
print '<td>'.$langs->trans("TimesheetPreventAfterFollowingMonths").'</td>';
print '<td class="right" width="60" colspan="2">';
print '<input type="number" id="timesheetFreezeDuration" name="timesheetFreezeDuration" min="0" step="1" value="'.$conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS.'"/>&nbsp;';
print '<input type="submit" class="button" name="PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS" value="'.$langs->trans("Modify").'">';
print '</td>';
print '</tr>';
print '</table>';

View File

@ -1095,6 +1095,18 @@ class Task extends CommonObject
if (isset($this->timespent_note)) $this->timespent_note = trim($this->timespent_note);
if (empty($this->timespent_datehour)) $this->timespent_datehour = $this->timespent_date;
if (! empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) {
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
$restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm');
if ($this->timespent_date < $restrictBefore) {
$this->error = $langs->trans('TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS);
$this->errors[] = $this->error;
return -1;
}
}
$this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_time (";