Started to populate org_id on creation of expense items.
authorNik Okuntseff <support@anuko.com>
Sat, 17 Nov 2018 18:44:00 +0000 (18:44 +0000)
committerNik Okuntseff <support@anuko.com>
Sat, 17 Nov 2018 18:44:00 +0000 (18:44 +0000)
WEB-INF/lib/ttExpenseHelper.class.php
WEB-INF/templates/footer.tpl
dbinstall.php
expense_edit.php
expenses.php
mobile/expense_edit.php
mobile/expenses.php

index 6d3128f..7c0d83f 100644 (file)
@@ -34,9 +34,11 @@ class ttExpenseHelper {
     global $user;
     $mdb2 = getConnection();
 
+    $user_id = $user->getActiveUser();
+    $group_id = $user->getActiveGroup();
+    $org_id = $user->org_id;
+
     $date = $fields['date'];
-    $user_id = (int) $fields['user_id'];
-    $group_id = (int) $fields['group_id'];
     $client_id = $fields['client_id'];
     $project_id = $fields['project_id'];
     $name = $fields['name'];
@@ -46,15 +48,12 @@ class ttExpenseHelper {
     $paid = (int) $fields['paid'];
     $created = ', now(), '.$mdb2->quote($_SERVER['REMOTE_ADDR']).', '.$mdb2->quote($user->id);
 
-    $sql = "insert into tt_expense_items (date, user_id, group_id, client_id, project_id, name, cost, invoice_id, paid, created, created_ip, created_by, status) ".
-      "values (".$mdb2->quote($date).", $user_id, $group_id, ".$mdb2->quote($client_id).", ".$mdb2->quote($project_id).
+    $sql = "insert into tt_expense_items".
+      " (date, user_id, group_id, org_id, client_id, project_id, name, cost, invoice_id, paid, created, created_ip, created_by, status)".
+      " values (".$mdb2->quote($date).", $user_id, $group_id, $org_id, ".$mdb2->quote($client_id).", ".$mdb2->quote($project_id).
       ", ".$mdb2->quote($name).", ".$mdb2->quote($cost).", ".$mdb2->quote($invoice_id).", $paid $created, ".$mdb2->quote($status).")";
     $affected = $mdb2->exec($sql);
-    if (is_a($affected, 'PEAR_Error'))
-      return false;
-
-    $id = $mdb2->lastInsertID('tt_expense_items', 'id');
-    return $id;
+    return (!is_a($affected, 'PEAR_Error'));
   }
 
   // update - updates a record in tt_expense_items table.
@@ -82,12 +81,8 @@ class ttExpenseHelper {
       ", project_id = ".$mdb2->quote($project_id).", name = ".$mdb2->quote($name).
       ", cost = ".$mdb2->quote($cost)."$paid_part $modified_part, invoice_id = ".$mdb2->quote($invoice_id).
       " WHERE id = $id";
-
     $affected = $mdb2->exec($sql);
-    if (is_a($affected, 'PEAR_Error'))
-      return false;
-
-    return true;
+    return (!is_a($affected, 'PEAR_Error'));
   }
 
   // markDeleted - marks an item as deleted in tt_expense_items table.
@@ -96,10 +91,7 @@ class ttExpenseHelper {
 
     $sql = "update tt_expense_items set status = NULL where id = $id and user_id = $user_id";
     $affected = $mdb2->exec($sql);
-    if (is_a($affected, 'PEAR_Error'))
-      return false;
-
-    return true;
+    return (!is_a($affected, 'PEAR_Error'));
   }
 
   // getTotalForDay - gets total expenses for a user for a specific date.
index 58b036c..0fa85da 100644 (file)
@@ -12,7 +12,7 @@
       <br>
       <table cellspacing="0" cellpadding="4" width="100%" border="0">
         <tr>
-          <td align="center">&nbsp;Anuko Time Tracker 1.18.17.4444 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.18.17.4445 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
             <a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
             <a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
             <a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>
index e8dc454..437dac2 100644 (file)
@@ -1005,6 +1005,7 @@ if ($_POST) {
     setChange("UPDATE `tt_predefined_expenses` inner join `tt_site_config` sc on (sc.param_name = 'version_db' and sc.param_value = '1.18.16') set org_id = group_id where org_id is null");
     setChange("ALTER TABLE `tt_expense_items` ADD `org_id` int(11) default NULL AFTER `group_id`");
     setChange("UPDATE `tt_site_config` SET param_value = '1.18.17', modified = now() where param_name = 'version_db' and param_value = '1.18.16'");
+    setChange("UPDATE `tt_expense_items` inner join `tt_site_config` sc on (sc.param_name = 'version_db' and sc.param_value = '1.18.17') set org_id = group_id where org_id is null");
 
     // TODO: this does not work as we just introduced group_id and it is NULL. Same for tt_project_task_binds. Improve.
     // setChange("UPDATE `tt_user_project_binds` inner join `tt_site_config` sc on (sc.param_name = 'version_db' and sc.param_value = '1.18.12') set org_id = group_id where org_id is null");
index 353f5ce..0c7cee5 100644 (file)
@@ -205,8 +205,8 @@ if ($request->isPost()) {
 
     // Now, a new insert.
     if ($err->no()) {
-      if (ttExpenseHelper::insert(array('date'=>$new_date->toString(DB_DATEFORMAT),'user_id'=>$user->getActiveUser(),'group_id'=>$user->getActiveGroup(),
-        'client_id'=>$cl_client,'project_id'=>$cl_project,'name'=>$cl_item_name,'cost'=>$cl_cost,'status'=>1))) {
+      if (ttExpenseHelper::insert(array('date'=>$new_date->toString(DB_DATEFORMAT),'client_id'=>$cl_client,
+          'project_id'=>$cl_project,'name'=>$cl_item_name,'cost'=>$cl_cost,'status'=>1))) {
         header('Location: expenses.php?date='.$new_date->toString(DB_DATEFORMAT));
         exit();
       } else
index fa45ad4..69d8ae7 100644 (file)
@@ -188,8 +188,8 @@ if ($request->isPost()) {
 
     // Insert record.
     if ($err->no()) {
-      if (ttExpenseHelper::insert(array('date'=>$cl_date,'user_id'=>$user->getActiveUser(),'group_id'=>$user->getActiveGroup(),
-        'client_id'=>$cl_client,'project_id'=>$cl_project,'name'=>$cl_item_name,'cost'=>$cl_cost,'status'=>1))) {
+      if (ttExpenseHelper::insert(array('date'=>$cl_date,'client_id'=>$cl_client,
+          'project_id'=>$cl_project,'name'=>$cl_item_name,'cost'=>$cl_cost,'status'=>1))) {
         header('Location: expenses.php');
         exit();
       } else
index 338e6c7..61edca2 100644 (file)
@@ -200,8 +200,8 @@ if ($request->isPost()) {
 
     // Now, a new insert.
     if ($err->no()) {
-      if (ttExpenseHelper::insert(array('date'=>$new_date->toString(DB_DATEFORMAT),'user_id'=>$user->getActiveUser(),'group_id'=>$user->getActiveGroup(),
-        'client_id'=>$cl_client,'project_id'=>$cl_project,'name'=>$cl_item_name,'cost'=>$cl_cost,'status'=>1))) {
+      if (ttExpenseHelper::insert(array('date'=>$new_date->toString(DB_DATEFORMAT),'client_id'=>$cl_client,
+          'project_id'=>$cl_project,'name'=>$cl_item_name,'cost'=>$cl_cost,'status'=>1))) {
         header('Location: expenses.php?date='.$new_date->toString(DB_DATEFORMAT));
         exit();
       } else
index 25a1c60..97232f7 100644 (file)
@@ -192,8 +192,8 @@ if ($request->isPost()) {
 
     // Insert record.
     if ($err->no()) {
-      if (ttExpenseHelper::insert(array('date'=>$cl_date,'user_id'=>$user->getActiveUser(),'group_id'=>$user->getActiveGroup(),
-        'client_id'=>$cl_client,'project_id'=>$cl_project,'name'=>$cl_item_name,'cost'=>$cl_cost,'status'=>1))) {
+      if (ttExpenseHelper::insert(array('date'=>$cl_date,'client_id'=>$cl_client,
+          'project_id'=>$cl_project,'name'=>$cl_item_name,'cost'=>$cl_cost,'status'=>1))) {
         header('Location: expenses.php');
         exit();
       } else