From 1e49bbdab2c6d229a22ed10495b526ac703b0be8 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Sat, 17 Nov 2018 18:44:00 +0000 Subject: [PATCH] Started to populate org_id on creation of expense items. --- WEB-INF/lib/ttExpenseHelper.class.php | 28 ++++++++++----------------- WEB-INF/templates/footer.tpl | 2 +- dbinstall.php | 1 + expense_edit.php | 4 ++-- expenses.php | 4 ++-- mobile/expense_edit.php | 4 ++-- mobile/expenses.php | 4 ++-- 7 files changed, 20 insertions(+), 27 deletions(-) diff --git a/WEB-INF/lib/ttExpenseHelper.class.php b/WEB-INF/lib/ttExpenseHelper.class.php index 6d3128fd..7c0d83ff 100644 --- a/WEB-INF/lib/ttExpenseHelper.class.php +++ b/WEB-INF/lib/ttExpenseHelper.class.php @@ -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. diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 58b036ca..0fa85daa 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.17.4444 | Copyright © Anuko | +  Anuko Time Tracker 1.18.17.4445 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/dbinstall.php b/dbinstall.php index e8dc454b..437dac2e 100644 --- a/dbinstall.php +++ b/dbinstall.php @@ -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"); diff --git a/expense_edit.php b/expense_edit.php index 353f5ce5..0c7cee5c 100644 --- a/expense_edit.php +++ b/expense_edit.php @@ -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 diff --git a/expenses.php b/expenses.php index fa45ad44..69d8ae72 100644 --- a/expenses.php +++ b/expenses.php @@ -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 diff --git a/mobile/expense_edit.php b/mobile/expense_edit.php index 338e6c77..61edca26 100644 --- a/mobile/expense_edit.php +++ b/mobile/expense_edit.php @@ -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 diff --git a/mobile/expenses.php b/mobile/expenses.php index 25a1c602..97232f70 100644 --- a/mobile/expenses.php +++ b/mobile/expenses.php @@ -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 -- 2.20.1