global $user;
global $i18n;
+ // Determine these once as they are used in multiple places in this function.
+ $canViewReports = $user->can('view_reports');
+ $isClient = $user->isClient();
+
$items = ttReportHelper::getItems($bean);
$group_by = $bean->getAttribute('group_by');
if ($group_by && 'no_grouping' != $group_by)
}
if ($bean->getAttribute('chcost')) {
$body .= '<td style="'.$cellRightAlignedSubtotal.'">';
- $body .= ($user->canManageTeam() || $user->isClient()) ? $subtotal['cost'] : $subtotal['expenses'];
+ $body .= ($canViewReports || $isClient) ? $subtotal['cost'] : $subtotal['expenses'];
$body .= '</td>';
}
$body .= '</tr>';
}
if ($bean->getAttribute('chcost')) {
$body .= '<td nowrap style="'.$cellRightAlignedSubtotal.'">'.htmlspecialchars($user->currency).' ';
- $body .= ($user->canManageTeam() || $user->isClient()) ? $totals['cost'] : $totals['expenses'];
+ $body .= ($canViewReports || $isClient) ? $totals['cost'] : $totals['expenses'];
$body .= '</td>';
}
$body .= '</tr>';
$body .= '<table border="0" cellpadding="4" cellspacing="0" width="100%">';
$body .= '<tr>';
$body .= '<td style="'.$tableHeader.'">'.$i18n->getKey('label.date').'</td>';
- if ($user->canManageTeam() || $user->isClient())
+ if ($canViewReports || $isClient)
$body .= '<td style="'.$tableHeader.'">'.$i18n->getKey('label.user').'</td>';
if ($bean->getAttribute('chclient'))
$body .= '<td style="'.$tableHeader.'">'.$i18n->getKey('label.client').'</td>';
$body .= '<tr style="'.$rowSubtotal.'">';
$body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.$i18n->getKey('label.subtotal').'</td>';
$subtotal_name = htmlspecialchars($subtotals[$prev_grouped_by]['name']);
- if ($user->canManageTeam() || $user->isClient()) $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.($group_by == 'user' ? $subtotal_name : '').'</td>';
+ if ($canViewReports || $isClient) $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.($group_by == 'user' ? $subtotal_name : '').'</td>';
if ($bean->getAttribute('chclient')) $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.($group_by == 'client' ? $subtotal_name : '').'</td>';
if ($bean->getAttribute('chproject')) $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.($group_by == 'project' ? $subtotal_name : '').'</td>';
if ($bean->getAttribute('chtask')) $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.($group_by == 'task' ? $subtotal_name : '').'</td>';
if ($bean->getAttribute('chnote')) $body .= '<td></td>';
if ($bean->getAttribute('chcost')) {
$body .= '<td style="'.$cellRightAlignedSubtotal.'">';
- $body .= ($user->canManageTeam() || $user->isClient()) ? $subtotals[$prev_grouped_by]['cost'] : $subtotals[$prev_grouped_by]['expenses'];
+ $body .= ($canViewReports || $isClient) ? $subtotals[$prev_grouped_by]['cost'] : $subtotals[$prev_grouped_by]['expenses'];
$body .= '</td>';
}
if ($bean->getAttribute('chpaid')) $body .= '<td></td>';
$row_style = ($row_style == $rowItem) ? $rowItemAlt : $rowItem;
$body .= '<tr style="'.$row_style.'">';
$body .= '<td style="'.$cellLeftAligned.'">'.$record['date'].'</td>';
- if ($user->canManageTeam() || $user->isClient())
+ if ($canViewReports || $isClient)
$body .= '<td style="'.$cellLeftAligned.'">'.htmlspecialchars($record['user']).'</td>';
if ($bean->getAttribute('chclient'))
$body .= '<td style="'.$cellLeftAligned.'">'.htmlspecialchars($record['client']).'</td>';
$body .= '<tr style="'.$rowSubtotal.'">';
$body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.$i18n->getKey('label.subtotal').'</td>';
$subtotal_name = htmlspecialchars($subtotals[$cur_grouped_by]['name']);
- if ($user->canManageTeam() || $user->isClient()) $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.($group_by == 'user' ? $subtotal_name : '').'</td>';
+ if ($canViewReports || $isClient) $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.($group_by == 'user' ? $subtotal_name : '').'</td>';
if ($bean->getAttribute('chclient')) $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.($group_by == 'client' ? $subtotal_name : '').'</td>';
if ($bean->getAttribute('chproject')) $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.($group_by == 'project' ? $subtotal_name : '').'</td>';
if ($bean->getAttribute('chtask')) $body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.($group_by == 'task' ? $subtotal_name : '').'</td>';
if ($bean->getAttribute('chnote')) $body .= '<td></td>';
if ($bean->getAttribute('chcost')) {
$body .= '<td style="'.$cellRightAlignedSubtotal.'">';
- $body .= ($user->canManageTeam() || $user->isClient()) ? $subtotals[$cur_grouped_by]['cost'] : $subtotals[$cur_grouped_by]['expenses'];
+ $body .= ($canViewReports || $isClient) ? $subtotals[$cur_grouped_by]['cost'] : $subtotals[$cur_grouped_by]['expenses'];
$body .= '</td>';
}
if ($bean->getAttribute('chpaid')) $body .= '<td></td>';
$body .= '<tr><td> </td></tr>';
$body .= '<tr style="'.$rowSubtotal.'">';
$body .= '<td style="'.$cellLeftAlignedSubtotal.'">'.$i18n->getKey('label.total').'</td>';
- if ($user->canManageTeam() || $user->isClient()) $body .= '<td></td>';
+ if ($canViewReports || $isClient) $body .= '<td></td>';
if ($bean->getAttribute('chclient')) $body .= '<td></td>';
if ($bean->getAttribute('chproject')) $body .= '<td></td>';
if ($bean->getAttribute('chtask')) $body .= '<td></td>';
if ($bean->getAttribute('chnote')) $body .= '<td></td>';
if ($bean->getAttribute('chcost')) {
$body .= '<td nowrap style="'.$cellRightAlignedSubtotal.'">'.htmlspecialchars($user->currency).' ';
- $body .= ($user->canManageTeam() || $user->isClient()) ? $totals['cost'] : $totals['expenses'];
+ $body .= ($canViewReports || $isClient) ? $totals['cost'] : $totals['expenses'];
$body .= '</td>';
}
if ($bean->getAttribute('chpaid')) $body .= '<td></td>';