Adjusted time.php to honor note on separate row option.
[timetracker.git] / WEB-INF / lib / ttExpenseHelper.class.php
index bfc3ab7..e7da92c 100644 (file)
@@ -60,12 +60,12 @@ class ttExpenseHelper {
     global $user;
     $mdb2 = getConnection();
 
+    $user_id = $user->getUser();
     $group_id = $user->getGroup();
     $org_id = $user->org_id;
 
     $id = (int) $fields['id'];
     $date = $fields['date'];
-    $user_id = (int) $fields['user_id'];
     $client_id = $fields['client_id'];
     $project_id = $fields['project_id'];
     $name = $fields['name'];
@@ -110,24 +110,27 @@ class ttExpenseHelper {
     $group_id = $user->getGroup();
     $org_id = $user->org_id;
 
-    $sql = "select sum(cost) as sm from tt_expense_items".
+    $sql = "select sum(cost) as total from tt_expense_items".
       " where user_id = $user_id and group_id = $group_id and org_id = $org_id".
       " and date = ".$mdb2->quote($date)." and status = 1";
     $res = $mdb2->query($sql);
     if (!is_a($res, 'PEAR_Error')) {
       $val = $res->fetchRow();
-      $val['sm'] = str_replace('.', $user->getDecimalMark(), $val['sm']);
-      return $val['sm'];
+      $val['total'] = str_replace('.', $user->getDecimalMark(), $val['total']);
+      return $val['total'];
     }
     return false;
   }
 
   // getItem - retrieves an entry from tt_expense_items table.
-  static function getItem($id, $user_id) {
+  static function getItem($id) {
     global $user;
-
     $mdb2 = getConnection();
 
+    $user_id = $user->getUser();
+    $group_id = $user->getGroup();
+    $org_id = $user->org_id;
+
     $client_field = null;
     if ($user->isPluginEnabled('cl'))
       $client_field = ", c.name as client_name";
@@ -137,17 +140,17 @@ class ttExpenseHelper {
     if ($user->isPluginEnabled('cl'))
       $left_joins .= " left join tt_clients c on (ei.client_id = c.id)";
 
-    $sql = "select ei.id, ei.date, ei.client_id, ei.project_id, ei.name, ei.cost, ei.invoice_id, ei.paid $client_field, p.name as project_name
-      from tt_expense_items ei
-      $left_joins
-      where ei.id = $id and ei.user_id = $user_id and ei.status = 1";
+    $sql = "select ei.id, ei.date, ei.client_id, ei.project_id, ei.name, ei.cost, ei.invoice_id, ei.approved,".
+      " ei.paid $client_field, p.name as project_name".
+      " from tt_expense_items ei $left_joins".
+      " where ei.id = $id and ei.group_id = $group_id and ei.org_id = $org_id and ei.user_id = $user_id and ei.status = 1";
     $res = $mdb2->query($sql);
     if (!is_a($res, 'PEAR_Error')) {
       if (!$res->numRows()) {
         return false;
       }
       if ($val = $res->fetchRow()) {
-        $val['cost'] = str_replace('.', $user->decimal_mark, $val['cost']);
+        $val['cost'] = str_replace('.', $user->getDecimalMark(), $val['cost']);
         return $val;
       }
     }
@@ -155,11 +158,15 @@ class ttExpenseHelper {
   }
 
   // getItems - returns expense items for a user for a given date.
-  static function getItems($user_id, $date) {
+  static function getItems($date) {
     global $user;
+    $mdb2 = getConnection();
+
+    $user_id = $user->getUser();
+    $group_id = $user->getGroup();
+    $org_id = $user->org_id;
 
     $result = array();
-    $mdb2 = getConnection();
 
     $client_field = null;
     if ($user->isPluginEnabled('cl'))
@@ -170,16 +177,15 @@ class ttExpenseHelper {
     if ($user->isPluginEnabled('cl'))
       $left_joins .= " left join tt_clients c on (ei.client_id = c.id)";
 
-    $sql = "select ei.id as id $client_field, p.name as project, ei.name as item, ei.cost as cost,
-      ei.invoice_id from tt_expense_items ei
-      $left_joins
-      where ei.date = ".$mdb2->quote($date)." and ei.user_id = $user_id and ei.status = 1
-      order by ei.id";
+    $sql = "select ei.id as id $client_field, p.name as project, ei.name as item, ei.cost as cost,".
+      " ei.invoice_id, ei.approved from tt_expense_items ei $left_joins".
+      " where ei.date = ".$mdb2->quote($date)." and ei.user_id = $user_id".
+      " and ei.group_id = $group_id and ei.org_id = $org_id and ei.status = 1 order by ei.id";
 
     $res = $mdb2->query($sql);
     if (!is_a($res, 'PEAR_Error')) {
       while ($val = $res->fetchRow()) {
-       $val['cost'] = str_replace('.', $user->decimal_mark, $val['cost']);
+       $val['cost'] = str_replace('.', $user->getDecimalMark(), $val['cost']);
         $result[] = $val;
       }
     } else return false;