Uncompleted Indicators in other color for days past

Discussion forum about Anuko Time Tracker
Post Reply
Semper
Posts: 12
Joined: Mon May 20, 2019 6:25 pm

Uncompleted Indicators in other color for days past

Post by Semper » Wed May 22, 2019 7:31 pm

Hello.

When using TimeTracker in Punch Mode, the Uncompleted Indicators is a great way to see who is "in" and who is "out". However, the Uncompleted Indicator lumps together uncompleted records for Today and uncompleted records for previous days.

I would like the Uncompleted Indicators to show in a different color (purple?) those users who have uncompleted records from previous days (which would mean the user forgot to "puch out" yesterday or some previous day and therefore the user needs to be "pinged" by Top-Manager to find out what's going on with him).

I guess this is a feature request. How complex would be to implement such a thing?

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

Re: Uncompleted Indicators in other color for days past

Post by wrc » Thu May 23, 2019 1:08 pm

See users.php:

Code: Select all

$uncompleted_indicators = $user->getConfigOption('uncompleted_indicators');
if ($uncompleted_indicators) {
  // Check each active user if they have an uncompleted time entry.
  foreach ($active_users as $key => $active_user) {
    $active_users[$key]['has_uncompleted_entry'] = (bool) ttTimeHelper::getUncompleted($active_user['id']);
  }
  $smarty->assign('uncompleted_indicators', true);
}
See ttTimeHelper::getUncompleted:

Code: Select all

  // getUncompleted - retrieves an uncompleted record for user, if one exists.
  static function getUncompleted($user_id) {
    $mdb2 = getConnection();

    $sql = "select id, start from tt_log  
      where user_id = $user_id and start is not null and time_to_sec(duration) = 0 and status = 1";
    $res = $mdb2->query($sql);
    if (!is_a($res, 'PEAR_Error')) {
      if (!$res->numRows()) {
        return false;
      }
      if ($val = $res->fetchRow()) {
        return $val;
      }
    }
    return false;
  }
One has to write another function to obtain uncompleted entries that distinguishes today from past days, and modify the presentation part accordingly.

Semper
Posts: 12
Joined: Mon May 20, 2019 6:25 pm

Re: Uncompleted Indicators in other color for days past

Post by Semper » Thu May 23, 2019 9:29 pm

Thank you, wrc, for the hints.

I've already done it. I had to do these changes:

1. In file "WEB-INF/lib/ttTimeHelper.class.php", I changed line 653 so that it now is:

Code: Select all

$sql = "select id, start from tt_log where user_id = $user_id and start is not null and time_to_sec(duration) = 0 and status = 1 and date = CURDATE()";
2. In that same file, I added this new function:

Code: Select all

static function getUncompletedOld($user_id) {
	$mdb2 = getConnection();

	$sql = "select id, start from tt_log
	  where user_id = $user_id and start is not null and time_to_sec(duration) = 0 and status = 1 and date != CURDATE()";
	$res = $mdb2->query($sql);
	if (!is_a($res, 'PEAR_Error')) {
	  if (!$res->numRows()) {
		return false;
	  }
	  if ($val = $res->fetchRow()) {
		return $val;
	  }
	}
	return false;
}
3. In file "users.php" I changed this old block:

Code: Select all

if ($uncompleted_indicators) {
  // Check each active user if they have an uncompleted time entry.
  foreach ($active_users as $key => $active_user) {
	$active_users[$key]['has_uncompleted_entry'] = (bool) ttTimeHelper::getUncompleted($active_user['id']);
  }
  $smarty->assign('uncompleted_indicators', true);
}
...so that it now is like this:

Code: Select all

if ($uncompleted_indicators) {
  // Check each active user if they have an uncompleted time entry.
  foreach ($active_users as $key => $active_user) {
	$active_users[$key]['has_uncompleted_entry'] = (bool) ttTimeHelper::getUncompleted($active_user['id']);
	$active_users[$key]['has_uncompleted_entry_old'] = (bool) ttTimeHelper::getUncompletedOld($active_user['id']);
  }
  $smarty->assign('uncompleted_indicators', true);
  $smarty->assign('uncompleted_indicators_old', true);
}
4. In file "mobile/users.php" I changed this old block:

Code: Select all

if ($uncompleted_indicators) {
  // Check each active user if they have an uncompleted time entry.
  foreach ($active_users as $key => $active_user) {
	$active_users[$key]['has_uncompleted_entry'] = (bool) ttTimeHelper::getUncompleted($active_user['id']);
  }
  $smarty->assign('uncompleted_indicators', true);
}
...so that it now is like this:

Code: Select all

if ($uncompleted_indicators) {
  // Check each active user if they have an uncompleted time entry.
  foreach ($active_users as $key => $active_user) {
	$active_users[$key]['has_uncompleted_entry'] = (bool) ttTimeHelper::getUncompleted($active_user['id']);
	$active_users[$key]['has_uncompleted_entry_old'] = (bool) ttTimeHelper::getUncompletedOld($active_user['id']);
  }
  $smarty->assign('uncompleted_indicators', true);
  $smarty->assign('uncompleted_indicators_old', true);
}
5. In file "WEB-INF/templates/users.tpl" I changed this old block:

Code: Select all

{if $uncompleted_indicators}
	<span class="uncompleted-entry{if $u.has_uncompleted_entry} active{/if}"{if $u.has_uncompleted_entry} title="{$i18n.form.users.uncompleted_entry}"{/if}></span>
...so that it now is like this:

Code: Select all

{if $uncompleted_indicators || $uncompleted_indicators_old}
	<span class="uncompleted-entry{if $u.has_uncompleted_entry} active{else}{if $u.has_uncompleted_entry_old} old{/if}{/if}"{if $u.has_uncompleted_entry} title="{$i18n.form.users.uncompleted_entry}"{else}{if $u.has_uncompleted_entry_old} title="{$i18n.form.users.uncompleted_entry_old}"{/if}{/if}></span>
6. In file "WEB-INF/templates/mobile/users.tpl" I changed this old block:

Code: Select all

{if $uncompleted_indicators}
	<span class="uncompleted-entry{if $u.has_uncompleted_entry} active{/if}"{if $u.has_uncompleted_entry} title="{$i18n.form.users.uncompleted_entry}"{/if}></span>
...so that it now is like this:

Code: Select all

{if $uncompleted_indicators || $uncompleted_indicators_old}
	<span class="uncompleted-entry{if $u.has_uncompleted_entry} active{else}{if $u.has_uncompleted_entry_old} old{/if}{/if}"{if $u.has_uncompleted_entry} title="{$i18n.form.users.uncompleted_entry}"{else}{if $u.has_uncompleted_entry_old} title="{$i18n.form.users.uncompleted_entry_old}"{/if}{/if}></span>
7. In file "default.css" I added this new line:

Code: Select all

.uncompleted-entry.old { background-color: blue; }
8. And finally in "WEB-INF/resources/en.lang.php" I changed this line:

Code: Select all

'form.users.uncompleted_entry' => 'User has an uncompleted time entry for Today',
...and I added this new line:

Code: Select all

'form.users.uncompleted_entry_old' => 'User has an uncompleted time entry for some previous day',

With these changes, in the Users tab a red icon goes next to users with an uncompleted "punch in" for today, and a blue icon goes next to users with an uncompleted "punch in" for any previous day.

But I have a problem: the blue icon only appears when I go to the Users tab with a user with Top-Manager, Manager or Co-Manager rol, but not when I go to the Users tab with some user with the "User" rol. So perhaps I need to give permission to run the new getUncompletedOld function to the "view_users" right? Any help is appreciated with that.

Nik
Posts: 477
Joined: Wed May 26, 2010 5:55 pm

Re: Uncompleted Indicators in other color for days past

Post by Nik » Fri May 24, 2019 7:21 pm

This approach breaks other things as ttTimeHelper::getUncompleted() is used in other places.

Uncompleted indicators, by current design, are shown to users with the manage_users right, which the default User role does not have.

Another problem is the timing of Today, as you use server time here, while normally this should be local (browser) time.

However, the current approach of using browser time for time entry has its own issues as local system time can be changed.

A better approach is probably to try to introduce configurable timezones for groups and users with all complexities that it brings in. But this is rather a big change that touches many areas of Time Tracker and requires redesign / refactoring.

Nik
Posts: 477
Joined: Wed May 26, 2010 5:55 pm

Re: Uncompleted Indicators in other color for days past

Post by Nik » Fri May 24, 2019 9:44 pm

In version 1.19.4.5012 I added a capability to see uncompleted indicators to users with the view_users access right (regular User role).

See WEB-INF/templates/users.tpl - the code for regular users is at the bottom:

Code: Select all

{else}
      <table cellspacing="1" cellpadding="3" border="0" width="100%">
        <tr>
          <td width="35%" class="tableHeader">{$i18n.label.person_name}</td>
          <td width="35%" class="tableHeader">{$i18n.label.login}</td>
          <td class="tableHeader">{$i18n.form.users.role}</td>
        </tr>
  {foreach $active_users as $u}
        <tr bgcolor="{cycle values="#f5f5f5,#ffffff"}">
          <td>
    {if $uncompleted_indicators}
            <span class="uncompleted-entry{if $u.has_uncompleted_entry} active{/if}"{if $u.has_uncompleted_entry} title="{$i18n.form.users.uncompleted_entry}"{/if}></span>
    {/if}
            {$u.name|escape}
          </td>
          <td>{$u.login|escape}</td>
          <td>{$u.role_name|escape}</td>
        </tr>
  {/foreach}
      </table>
{/if}
Hope it helps.

Semper
Posts: 12
Joined: Mon May 20, 2019 6:25 pm

Re: Uncompleted Indicators in other color for days past

Post by Semper » Tue May 28, 2019 10:29 pm

Nik wrote:
Fri May 24, 2019 9:44 pm
In version 1.19.4.5012 I added a capability to see uncompleted indicators to users with the view_users access right (regular User role).
Thank you. That is very helpful when using Time Tracker in "punch mode".

Post Reply