]> wagnertech.de Git - timetracker.git/blobdiff - WEB-INF/lib/ttReportHelper.class.php
Added a mechanism to assign report items to timesheets.
[timetracker.git] / WEB-INF / lib / ttReportHelper.class.php
index abb5ab9e60cf05efbd08a19fc13bf826db89081a..ceaee4b011f530c00cd77c5ab676047cb2c5823d 100644 (file)
@@ -629,6 +629,26 @@ class ttReportHelper {
     }
   }
 
+  // The assignToTimesheet assigns a set of tt_log records to a specific timesheet.
+  static function assignToTimesheet($timesheet_id, $time_log_ids) {
+    global $user;
+    $mdb2 = getConnection();
+
+    $user_id = $user->getUser();
+    $group_id = $user->getGroup();
+    $org_id = $user->org_id;
+
+    if ($time_log_ids) {
+      $sql = "update tt_log l".
+        // TODO: inner join does not work properly for de-assignment. Improve.
+        // " inner join tt_timesheets ts on (ts.id = $timesheet_id and ts.approve_status is null)".
+        " set l.timesheet_id = ".$mdb2->quote($timesheet_id).
+        " where l.id in(".join(', ', $time_log_ids).") and l.user_id = $user_id and l.group_id = $group_id and l.org_id = $org_id";
+      $affected = $mdb2->exec($sql);
+      if (is_a($affected, 'PEAR_Error')) die($affected->getMessage());
+    }
+  }
+
   // The markApproved marks a set of records as either approved or unapproved.
   static function markApproved($time_log_ids, $expense_item_ids, $approved = true) {
     global $user;