Separated users section on reports in 2 for active and inactive users.
authorNik Okuntseff <support@anuko.com>
Fri, 19 Apr 2019 15:36:25 +0000 (15:36 +0000)
committerNik Okuntseff <support@anuko.com>
Fri, 19 Apr 2019 15:36:38 +0000 (15:36 +0000)
WEB-INF/lib/ttFavReportHelper.class.php
WEB-INF/lib/ttGroupHelper.class.php
WEB-INF/lib/ttReportHelper.class.php
WEB-INF/lib/ttUser.class.php
WEB-INF/templates/footer.tpl
WEB-INF/templates/reports.tpl
reports.php

index 8b9f405..a3e130c 100644 (file)
@@ -72,6 +72,7 @@ class ttFavReportHelper {
     }
     return false;
   }
+
   // getReport - returns a report identified by its id.
   // TODO: get rid of this function by encapsulating all cron related tasks in its own class.
   // Because cron works for all orgs and we want this class to always work in context of
@@ -225,10 +226,16 @@ class ttFavReportHelper {
 
     if (!$bean->getAttribute('chtotalsonly')) $bean->setAttribute('chtotalsonly', 0);
 
-    $users_in_bean = $bean->getAttribute('users');
-    if ($users_in_bean && is_array($users_in_bean)) {
-      $users = join(',', $users_in_bean);
+    $active_users_in_bean = $bean->getAttribute('users_active');
+    if ($active_users_in_bean && is_array($active_users_in_bean)) {
+      $users = join(',', $active_users_in_bean);
+    }
+    $inactive_users_in_bean = $bean->getAttribute('users_inactive');
+    if ($inactive_users_in_bean && is_array($inactive_users_in_bean)) {
+      if ($users) $users .= ',';
+      $users .= join(',', $inactive_users_in_bean);
     }
+
     if ($bean->getAttribute('start_date')) {
       $dt = new DateAndTime($user->getDateFormat(), $bean->getAttribute('start_date'));
       $from = $dt->toString(DB_DATEFORMAT);
@@ -322,7 +329,8 @@ class ttFavReportHelper {
       $bean->setAttribute('invoice', $val['invoice']);
       $bean->setAttribute('paid_status', $val['paid_status']);
       $bean->setAttribute('timesheet', $val['timesheet']);
-      $bean->setAttribute('users', explode(',', $val['users']));
+      $bean->setAttribute('users_active', explode(',', $val['users']));
+      $bean->setAttribute('users_inactive', explode(',', $val['users']));
       $bean->setAttribute('period', $val['period']);
       if ($val['period_start']) {
         $dt = new DateAndTime(DB_DATEFORMAT, $val['period_start']);
index 4bc7164..167c620 100644 (file)
@@ -637,19 +637,22 @@ class ttGroupHelper {
   }
 
   // The getUsersForClient obtains all active and inactive users in a group that are relevant to a client.
-  static function getUsersForClient() {
+  static function getUsersForClient($options) {
     global $user;
     $mdb2 = getConnection();
 
     $group_id = $user->getGroup();
     $org_id = $user->org_id;
 
+    if (isset($options['status']))
+      $where_part = 'where u.status = '.(int)$options['status'];
+    else
+      $where_part = 'where u.status is not null';
+
     $sql = "select u.id, u.name from tt_user_project_binds upb".
       " inner join tt_client_project_binds cpb on (upb.project_id = cpb.project_id and cpb.client_id = $user->client_id)".
       " inner join tt_users u on (u.id = upb.user_id and u.group_id = $group_id and u.org_id = $org_id)".
-      " where (u.status = 1 or u.status = 0)".
-      " group by u.id".
-      " order by upper(u.name)";
+      " $where_part group by u.id order by upper(u.name)";
     $res = $mdb2->query($sql);
     $user_list = array();
     if (is_a($res, 'PEAR_Error'))
index 088280c..9c6dfb0 100644 (file)
@@ -1155,7 +1155,18 @@ class ttReportHelper {
     if ($user->isPluginEnabled('ap') && $user->isClient() && !$user->can('view_client_unapproved'))
       $options['approved'] = 1; // Restrict clients to approved records only.
     $options['timesheet'] = $bean->getAttribute('timesheet');
-    if (is_array($bean->getAttribute('users'))) $options['users'] = join(',', $bean->getAttribute('users'));
+
+    $active_users_in_bean = $bean->getAttribute('users_active');
+    if ($active_users_in_bean && is_array($active_users_in_bean)) {
+      $users = join(',', $active_users_in_bean);
+    }
+    $inactive_users_in_bean = $bean->getAttribute('users_inactive');
+    if ($inactive_users_in_bean && is_array($inactive_users_in_bean)) {
+      if ($users) $users .= ',';
+      $users .= join(',', $inactive_users_in_bean);
+    }
+    if ($users) $options['users'] = $users;
+
     $options['period'] = $bean->getAttribute('period');
     $options['period_start'] = $bean->getAttribute('start_date');
     $options['period_end'] = $bean->getAttribute('end_date');
@@ -1187,13 +1198,19 @@ class ttReportHelper {
     global $user;
 
     // Check users.
-    $users_in_bean = $bean->getAttribute('users');
-    if (is_array($users_in_bean)) {
+    $active_users_in_bean = $bean->getAttribute('users_active');
+    $inactive_users_in_bean = $bean->getAttribute('users_inactive');
+    if (is_array($active_users_in_bean) || is_array($inactive_users_in_bean)) {
       $users_in_group = ttGroupHelper::getUsers();
       foreach ($users_in_group as $user_in_group) {
         $valid_ids[] = $user_in_group['id'];
       }
-      foreach ($users_in_bean as $user_in_bean) {
+      foreach ($active_users_in_bean as $user_in_bean) {
+        if (!in_array($user_in_bean, $valid_ids)) {
+          return false;
+        }
+      }
+      foreach ($inactive_users_in_bean as $user_in_bean) {
         if (!in_array($user_in_bean, $valid_ids)) {
           return false;
         }
index 33a32dc..2d45101 100644 (file)
@@ -424,7 +424,7 @@ class ttUser {
 
     $left_joins = null;
     if (isset($options['max_rank']) || $skipClients || isset($options['include_role']))
-        $left_joins .= ' left join tt_roles r on (u.role_id = r.id)';
+      $left_joins .= ' left join tt_roles r on (u.role_id = r.id)';
 
     $where_part = " where u.org_id = $org_id and u.group_id = $group_id";
     if (isset($options['status']))
index 99115a6..eea5a85 100644 (file)
@@ -12,7 +12,7 @@
       <br>
       <table cellspacing="0" cellpadding="4" width="100%" border="0">
         <tr>
-          <td align="center">&nbsp;Anuko Time Tracker 1.19.0.4959 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.19.1.4960 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
             <a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
             <a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
             <a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>
index 3f1dea0..c79425e 100644 (file)
@@ -300,12 +300,20 @@ function handleCheckboxes() {
             </table>
           </td>
         </tr>
-{if $show_users}
+{if $show_active_users}
         <tr>
-          <td colspan="3"><b>{$i18n.label.users}</b></td>
+          <td colspan="3"><b>{$i18n.form.users.active_users}</b></td>
         </tr>
         <tr>
-          <td colspan="3">{$forms.reportForm.users.control}</td>
+          <td colspan="3">{$forms.reportForm.users_active.control}</td>
+        </tr>
+{/if}
+{if $show_inactive_users}
+        <tr>
+          <td colspan="3"><b>{$i18n.form.users.inactive_users}</b></td>
+        </tr>
+        <tr>
+          <td colspan="3">{$forms.reportForm.users_inactive.control}</td>
         </tr>
 {/if}
         <tr>
index c191de9..fe545b2 100644 (file)
@@ -216,17 +216,25 @@ if ($showUsers) {
   if ($user->can('view_reports') || $user->can('view_all_reports')) {
     $rank = $user->getMaxRankForGroup($user->getGroup());
     if ($user->can('view_all_reports')) $max_rank = MAX_RANK;
-    if ($user->can('view_own_reports'))
-      $options = array('max_rank'=>$max_rank,'include_self'=>true);
-    else
-      $options = array('max_rank'=>$max_rank);
-    $users = $user->getUsers($options); // Active and inactive users.
+    if ($user->can('view_own_reports')) {
+      $options_active = array('max_rank'=>$max_rank,'include_self'=>true,'status'=>ACTIVE);
+      $options_inactive = array('max_rank'=>$max_rank,'include_self'=>true,'status'=>INACTIVE);
+    } else {
+      $options_active = array('max_rank'=>$max_rank,'status'=>ACTIVE);
+      $options_inactive = array('max_rank'=>$max_rank,'status'=>INACTIVE);
+    }
+    $active_users = $user->getUsers($options_active);
+    $inactive_users = $user->getUsers($options_inactive);
+  }
+  elseif ($user->isClient()) {
+    $options_active = array('status'=>ACTIVE);
+    $options_inactive = array('status'=>INACTIVE);
+    $active_users = ttGroupHelper::getUsersForClient($options_active);
+    $inactive_users = ttGroupHelper::getUsersForClient($options_inactive);
   }
-  elseif ($user->isClient())
-    $users = ttGroupHelper::getUsersForClient(); // Active and inactive users for clients.
 
-  foreach ($users as $single_user) {
-    $user_list[$single_user['id']] = $single_user['name'];
+  foreach ($active_users as $single_user) {
+    $user_list_active[$single_user['id']] = $single_user['name'];
     $projects = ttProjectHelper::getAssignedProjects($single_user['id']);
     if ($projects) {
       foreach ($projects as $single_project) {
@@ -234,10 +242,27 @@ if ($showUsers) {
       }
     }
   }
-  $row_count = ceil(count($user_list)/3);
+  $row_count = ceil(count($user_list_active)/3);
   $form->addInput(array('type'=>'checkboxgroup',
-    'name'=>'users',
-    'data'=>$user_list,
+    'name'=>'users_active',
+    'data'=>$user_list_active,
+    'layout'=>'V',
+    'groupin'=>$row_count,
+    'style'=>'width: 100%;'));
+
+    foreach ($inactive_users as $single_user) {
+    $user_list_inactive[$single_user['id']] = $single_user['name'];
+    $projects = ttProjectHelper::getAssignedProjects($single_user['id']);
+    if ($projects) {
+      foreach ($projects as $single_project) {
+        $assigned_projects[$single_user['id']][] = $single_project['id'];
+      }
+    }
+  }
+  $row_count = ceil(count($user_list_inactive)/3);
+  $form->addInput(array('type'=>'checkboxgroup',
+    'name'=>'users_inactive',
+    'data'=>$user_list_inactive,
     'layout'=>'V',
     'groupin'=>$row_count,
     'style'=>'width: 100%;'));
@@ -332,7 +357,7 @@ $bean = new ActionForm('reportBean', $form, $request);
 
 if ($request->isGet() && !$bean->isSaved()) {
   // No previous form data were found in session. Use the following default values.
-  $form->setValueByElement('users', array_keys($user_list));
+  $form->setValueByElement('users_active', array_keys($user_list_active));
   $period = new Period(INTERVAL_THIS_MONTH, new DateAndTime($user->getDateFormat()));
   $form->setValueByElement('start_date', $period->getStartDate());
   $form->setValueByElement('end_date', $period->getEndDate());
@@ -374,8 +399,10 @@ if ($request->isPost()) {
       ttFavReportHelper::loadReport($bean);
 
       // If user selected no favorite report - mark all user checkboxes (most probable scenario).
-      if ($bean->getAttribute('favorite_report') == -1)
-        $form->setValueByElement('users', array_keys($user_list));
+      if ($bean->getAttribute('favorite_report') == -1) {
+        $form->setValueByElement('users_active', array_keys($user_list_active));
+        $form->setValueByElement('users_inactive', false);
+      }
 
       // Save form data in session for future use.
       $bean->saveBean();
@@ -457,7 +484,8 @@ $smarty->assign('show_invoice_checkbox', $showInvoiceCheckbox);
 $smarty->assign('show_paid_status', $showPaidStatus);
 $smarty->assign('show_timesheet_dropdown', $showTimesheetDropdown);
 $smarty->assign('show_timesheet_checkbox', $showTimesheetCheckbox);
-$smarty->assign('show_users', $showUsers);
+$smarty->assign('show_active_users', $showUsers && $active_users);
+$smarty->assign('show_inactive_users', $showUsers && $inactive_users);
 $smarty->assign('show_start', $showStart);
 $smarty->assign('show_finish', $showFinish);
 $smarty->assign('show_work_units', $showWorkUnits);