global $user;
$mdb2 = getConnection();
+ // Determine these once as they are used in multiple places in this function.
+ $canViewReports = $user->can('view_reports');
+ $isClient = $user->isClient();
+
$group_by_option = $bean->getAttribute('group_by');
$convertTo12Hour = ('%I:%M %p' == $user->time_format) && ($bean->getAttribute('chstart') || $bean->getAttribute('chfinish'));
array_push($fields, 'l.id as id');
array_push($fields, '1 as type'); // Type 1 is for tt_log entries.
array_push($fields, 'l.date as date');
- if($user->can('view_reports') || $user->isClient())
+ if($canViewReports || $isClient)
array_push($fields, 'u.name as user');
// Add client name if it is selected.
if ($bean->getAttribute('chclient') || 'client' == $group_by_option)
array_push($fields, "null as expense");
}
// Add paid status.
- if ($user->canManageTeam() && $bean->getAttribute('chpaid'))
+ if ($canViewReports && $bean->getAttribute('chpaid'))
array_push($fields, 'l.paid as paid');
// Add invoice name if it is selected.
- if (($user->canManageTeam() || $user->isClient()) && $bean->getAttribute('chinvoice'))
+ if (($canViewReports || $isClient) && $bean->getAttribute('chinvoice'))
array_push($fields, 'i.name as invoice');
// Prepare sql query part for left joins.
$left_joins = null;
if ($bean->getAttribute('chclient') || 'client' == $group_by_option)
$left_joins .= " left join tt_clients c on (c.id = l.client_id)";
- if (($user->canManageTeam() || $user->isClient()) && $bean->getAttribute('chinvoice'))
+ if (($canViewReports || $isClient) && $bean->getAttribute('chinvoice'))
$left_joins .= " left join tt_invoices i on (i.id = l.invoice_id and i.status = 1)";
- if ($user->canManageTeam() || $user->isClient() || $user->isPluginEnabled('ex'))
+ if ($canViewReports || $isClient || $user->isPluginEnabled('ex'))
$left_joins .= " left join tt_users u on (u.id = l.user_id)";
if ($bean->getAttribute('chproject') || 'project' == $group_by_option)
$left_joins .= " left join tt_projects p on (p.id = l.project_id)";
array_push($fields, 'ei.id');
array_push($fields, '2 as type'); // Type 2 is for tt_expense_items entries.
array_push($fields, 'ei.date');
- if($user->canManageTeam() || $user->isClient())
+ if($canViewReports || $isClient)
array_push($fields, 'u.name as user');
// Add client name if it is selected.
if ($bean->getAttribute('chclient') || 'client' == $group_by_option)
array_push($fields, 'ei.cost as cost');
array_push($fields, 'ei.cost as expense');
// Add paid status.
- if ($user->canManageTeam() && $bean->getAttribute('chpaid'))
+ if ($canViewReports && $bean->getAttribute('chpaid'))
array_push($fields, 'ei.paid as paid');
// Add invoice name if it is selected.
- if (($user->canManageTeam() || $user->isClient()) && $bean->getAttribute('chinvoice'))
+ if (($canViewReports || $isClient) && $bean->getAttribute('chinvoice'))
array_push($fields, 'i.name as invoice');
// Prepare sql query part for left joins.
$left_joins = null;
- if ($user->canManageTeam() || $user->isClient())
+ if ($canViewReports || $isClient)
$left_joins .= " left join tt_users u on (u.id = ei.user_id)";
if ($bean->getAttribute('chclient') || 'client' == $group_by_option)
$left_joins .= " left join tt_clients c on (c.id = ei.client_id)";
if ($bean->getAttribute('chproject') || 'project' == $group_by_option)
$left_joins .= " left join tt_projects p on (p.id = ei.project_id)";
- if (($user->canManageTeam() || $user->isClient()) && $bean->getAttribute('chinvoice'))
+ if (($canViewReports || $isClient) && $bean->getAttribute('chinvoice'))
$left_joins .= " left join tt_invoices i on (i.id = ei.invoice_id and i.status = 1)";
$where = ttReportHelper::getExpenseWhere($bean);
$sort_part .= 'date';
else
$sort_part .= $group_by_option.', date';
- if (($user->canManageTeam() || $user->isClient()) && is_array($bean->getAttribute('users')) && 'user' != $group_by_option)
+ if (($canViewReports || $isClient) && is_array($bean->getAttribute('users')) && 'user' != $group_by_option)
$sort_part .= ', user, type';
if ($bean->getAttribute('chstart'))
$sort_part .= ', unformatted_start';