]> wagnertech.de Git - timetracker.git/blobdiff - WEB-INF/lib/ttReportHelper.class.php
Added timesheet name to report output.
[timetracker.git] / WEB-INF / lib / ttReportHelper.class.php
index 1b5fc6f10641fe630bbe225a2dc8013a6c8cacfd..6b84f4c7183dffb5c6355bfbb05cc42988792fe1 100644 (file)
@@ -43,6 +43,12 @@ class ttReportHelper {
     $group_id = $user->getGroup();
     $org_id = $user->org_id;
 
+    // A shortcut for timesheets.
+    if ($options['timesheet_id']) {
+      $where = " where l.timesheet_id = ".$options['timesheet_id']." and l.group_id = $group_id and l.org_id = $org_id";
+      return $where;
+    }
+
     // Prepare dropdown parts.
     $dropdown_parts = '';
     if ($options['client_id'])
@@ -89,6 +95,12 @@ class ttReportHelper {
     $group_id = $user->getGroup();
     $org_id = $user->org_id;
 
+    // A shortcut for timesheets.
+    if ($options['timesheet_id']) {
+      $where = " where ei.timesheet_id = ".$options['timesheet_id']." and ei.group_id = $group_id and ei.org_id = $org_id";
+      return $where;
+    }
+
     // Prepare dropdown parts.
     $dropdown_parts = '';
     if ($options['client_id'])
@@ -222,6 +234,9 @@ class ttReportHelper {
     // Add invoice name if it is selected.
     if (($canViewReports || $isClient) && $options['show_invoice'])
       array_push($fields, 'i.name as invoice');
+    // Add timesheet name if it is selected.
+    if ($options['show_timesheet'])
+      array_push($fields, 'ts.name as timesheet_name');
 
     // Prepare sql query part for left joins.
     $left_joins = null;
@@ -245,6 +260,8 @@ class ttReportHelper {
     }
     if ($includeCost && MODE_TIME != $trackingMode)
       $left_joins .= " left join tt_user_project_binds upb on (l.user_id = upb.user_id and l.project_id = upb.project_id)";
+    if ($options['show_timesheet'])
+      $left_joins .= " left join tt_timesheets ts on (l.timesheet_id = ts.id)";
 
     $where = ttReportHelper::getWhere($options);
 
@@ -301,6 +318,8 @@ class ttReportHelper {
       // Add invoice name if it is selected.
       if (($canViewReports || $isClient) && $options['show_invoice'])
         array_push($fields, 'i.name as invoice');
+      if ($options['show_timesheet'])
+        array_push($fields, 'ts.name as timesheet_name');
 
       // Prepare sql query part for left joins.
       $left_joins = null;
@@ -312,6 +331,8 @@ class ttReportHelper {
         $left_joins .= " left join tt_projects p on (p.id = ei.project_id)";
       if (($canViewReports || $isClient) && $options['show_invoice'])
         $left_joins .= " left join tt_invoices i on (i.id = ei.invoice_id and i.status = 1)";
+      if ($options['show_timesheet'])
+        $left_joins .= " left join tt_timesheets ts on (ei.timesheet_id = ts.id)";
 
       $where = ttReportHelper::getExpenseWhere($options);
 
@@ -991,6 +1012,7 @@ class ttReportHelper {
     $options['show_note'] = $bean->getAttribute('chnote');
     $options['show_custom_field_1'] = $bean->getAttribute('chcf_1');
     $options['show_work_units'] = $bean->getAttribute('chunits');
+    $options['show_timesheet'] = $bean->getAttribute('chtimesheet');
     $options['show_totals_only'] = $bean->getAttribute('chtotalsonly');
     $options['group_by1'] = $bean->getAttribute('group_by1');
     $options['group_by2'] = $bean->getAttribute('group_by2');