TimeTracker, Hours Daily limitation

Discussion forum about Anuko Time Tracker
Post Reply
nsauzay
Posts: 2
Joined: Tue Apr 01, 2014 8:35 pm

TimeTracker, Hours Daily limitation

Post by nsauzay » Tue Apr 01, 2014 8:39 pm

Hello,
is it possible to configure a daily limitation for wwork duration in anuko ?

wrc
Posts: 274
Joined: Tue May 25, 2010 8:30 pm

Re: TimeTracker, Hours Daily limitation

Post by wrc » Wed Apr 02, 2014 3:23 am

nsauzay wrote:Hello,
is it possible to configure a daily limitation for wwork duration in anuko ?
Not without modifying the current code. If you are looking at changing the duration field limit for a single entry (currently at 24 hours) look at the isValidDuration function in WEB-INF/lib/ttTimeHelper.class.php and change it accordingly. If you need to restrict the total time for multiple entries in any single day, you'll need to create a custom function for that.

nsauzay
Posts: 2
Joined: Tue Apr 01, 2014 8:35 pm

Re: TimeTracker, Hours Daily limitation

Post by nsauzay » Wed Apr 02, 2014 6:22 am

Ok thanks, is it a complex change ?

wrc
Posts: 274
Joined: Tue May 25, 2010 8:30 pm

Re: TimeTracker, Hours Daily limitation

Post by wrc » Thu Apr 03, 2014 1:17 am

nsauzay wrote:Ok thanks, is it a complex change ?
No.

canadidan
Posts: 1
Joined: Wed Sep 06, 2017 3:03 pm

Re: TimeTracker, Hours Daily limitation

Post by canadidan » Wed Sep 06, 2017 3:11 pm

(3 years later)

I've implemented this functionality here. Is it gross? Kinda. It seems to work as it should though.

Code: Select all

  static function isValidDuration($value) {
    if (strlen($value)==0 || !isset($value)) return false;

	$is_valid_duration_temp = false;
	$max_daily_hours = 8;
	
    if ($value == '24:00' || $value == '2400') $is_valid_duration_temp = true;

    if (preg_match('/^([0-1]{0,1}[0-9]|2[0-3]):?[0-5][0-9]$/', $value )) { // 0:00 - 23:59, 000 - 2359
      $is_valid_duration_temp = true;
    }
    if (preg_match('/^([0-1]{0,1}[0-9]|2[0-4])h?$/', $value )) { // 0, 1 ... 24
      $is_valid_duration_temp = true;
    }

    global $user;
    $localizedPattern = '/^([0-1]{0,1}[0-9]|2[0-3])?['.$user->decimal_mark.'][0-9]{1,4}h?$/';
    if (preg_match($localizedPattern, $value )) { // decimal values like 0.5, 1.25h, ... .. 23.9999h (or with comma)
      $is_valid_duration_temp = true;
    }
	
	if (!$is_valid_duration_temp) return false;
	
	global $user;
	$day_total = self::toMinutes(self::normalizeDuration(self::getTimeForDay($user->getActiveUser(), $_SESSION['date'])));
	$value_minutes = self::toMinutes(self::normalizeDuration($value));

	$record_duration = 0;
	if ( preg_match('/time_edit.php/', $_SERVER['HTTP_REFERER'] ) )
	{
		$record_duration = self::getRecord($_GET['id'], $user->getActiveUser());
		$record_duration = self::toMinutes(self::normalizeDuration($record_duration['duration']));
	}
	
	if (($day_total + $value_minutes - $record_duration) <= ($max_daily_hours * 60))
	{
		return true;
	}
	
    return false;
  }
It uses a temporary status variable for intermediate evals. If it fails the standard formatting checks, it will return false.

If it passes formatting, it will then ensure the daily total is below your threshold.

Simple enough?

Edit: bug fix for time_edit pages (because it's an update, not an addition)

Prsut
Posts: 1
Joined: Sun Dec 23, 2018 1:46 am

Re: TimeTracker, Hours Daily limitation

Post by Prsut » Sun Dec 23, 2018 6:07 am

I tried the above mod but it doesn't work for v 1.18.34 - did anybody get it to work :(
This is really a bug rather than a feature request.

Does anybody know how to set a limit so a user can not enter more than 24 hours of work a day?

wrc
Posts: 274
Joined: Tue May 25, 2010 8:30 pm

Re: TimeTracker, Hours Daily limitation

Post by wrc » Sun Dec 23, 2018 1:13 pm

Prsut wrote:
Sun Dec 23, 2018 6:07 am
Does anybody know how to set a limit so a user can not enter more than 24 hours of work a day?
There is currently a check for one entry not being more than 24 hours. But multiple entries are allowed. If a total limit must be enforced, code need to be modified, ideally in a flexible and a configurable way, as some would want their limit at 8 hours, some at 7:30, and some would not want any limit at all (believe it or not, including the limit on one entry). One real life example is entering time for client on the last day of the month for the entire group as one entry.

Best way to address this is probably via a customization request that would anticipate most of the above, including changes to db, export-import, required refactoring, writing config page or adding such option, etc. for the change.

Another way to improve is integrate this (nicely) with Monthly Quotas plugin that displays but not enforces, an over the quota situation.

Post Reply