Fixed editing org by admin, added a comment for imported subgroups.
[timetracker.git] / WEB-INF / lib / ttInvoiceHelper.class.php
index 0867ee1..042acd8 100644 (file)
@@ -32,34 +32,6 @@ import('DateAndTime');
 // Class ttInvoiceHelper is used for help with invoices.
 class ttInvoiceHelper {
 
-  // insert - inserts an invoice in database.
-  static function insert($fields)
-  {
-    $mdb2 = getConnection();
-
-    $group_id = (int) $fields['group_id'];
-    $org_id = (int) $fields['org_id'];
-    $name = $fields['name'];
-    if (!$name) return false;
-
-    $client_id = (int) $fields['client_id'];
-    $date = $fields['date'];
-    if (array_key_exists('status', $fields)) { // Key exists and may be NULL during migration of data.
-      $status_f = ', status';
-      $status_v = ', '.$mdb2->quote($fields['status']);
-    }
-
-    // Insert a new invoice record.
-    $sql = "insert into tt_invoices (group_id, org_id, name, date, client_id $status_f)".
-      " values($group_id, $org_id, ".$mdb2->quote($name).", ".$mdb2->quote($date).", $client_id $status_v)";
-    $affected = $mdb2->exec($sql);
-
-    if (is_a($affected, 'PEAR_Error')) return false;
-
-    $last_id = $mdb2->lastInsertID('tt_invoices', 'id');
-    return $last_id;
-  }
-
   // getInvoice - obtains invoice data from the database.
   static function getInvoice($invoice_id) {
     global $user;
@@ -285,18 +257,20 @@ class ttInvoiceHelper {
       }
     }
 
-    // sql part for project id.
-    if ($project_id) $project_part = " and ei.project_id = $project_id";
-
-    $sql = "select count(*) as num from tt_expense_items ei
-      where ei.client_id = $client_id $project_part and ei.invoice_id is NULL
-      and ei.date >= ".$mdb2->quote($start)." and ei.date <= ".$mdb2->quote($end)."
-      and ei.cost <> 0 and ei.status = 1";
-    $res = $mdb2->query($sql);
-    if (!is_a($res, 'PEAR_Error')) {
-      $val = $res->fetchRow();
-      if ($val['num']) {
-        return true;
+    if ($user->isPluginEnabled('ex')) {
+      // sql part for project id.
+      if ($project_id) $project_part = " and ei.project_id = $project_id";
+
+      $sql = "select count(*) as num from tt_expense_items ei
+        where ei.client_id = $client_id $project_part and ei.invoice_id is NULL
+        and ei.date >= ".$mdb2->quote($start)." and ei.date <= ".$mdb2->quote($end)."
+        and ei.cost <> 0 and ei.status = 1";
+      $res = $mdb2->query($sql);
+      if (!is_a($res, 'PEAR_Error')) {
+        $val = $res->fetchRow();
+        if ($val['num']) {
+          return true;
+        }
       }
     }