From f8292d356ef3ac53b2bb1183dd462f7c453c20e5 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Tue, 4 Dec 2018 20:13:57 +0000 Subject: [PATCH] More progress on refactoring expenses for subgroups. --- WEB-INF/lib/ttGroupHelper.class.php | 27 +++++++++++++++++++ .../lib/ttPredefinedExpenseHelper.class.php | 9 +++---- WEB-INF/lib/ttTeamHelper.class.php | 22 --------------- WEB-INF/templates/expense_delete.tpl | 4 +-- WEB-INF/templates/footer.tpl | 2 +- WEB-INF/templates/mobile/expense_delete.tpl | 4 +-- expense_delete.php | 6 ++++- expense_edit.php | 14 +++++----- expenses.php | 3 +-- mobile/expense_delete.php | 6 ++++- mobile/expense_edit.php | 3 +-- mobile/expenses.php | 3 +-- predefined_expenses.php | 4 +-- 13 files changed, 59 insertions(+), 48 deletions(-) diff --git a/WEB-INF/lib/ttGroupHelper.class.php b/WEB-INF/lib/ttGroupHelper.class.php index 9f9f4a2f..e5288a09 100644 --- a/WEB-INF/lib/ttGroupHelper.class.php +++ b/WEB-INF/lib/ttGroupHelper.class.php @@ -362,4 +362,31 @@ class ttGroupHelper { } return $result; } + + // getPredefinedExpenses - obtains predefined expenses for a group. + static function getPredefinedExpenses() { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $result = array(); + $sql = "select id, name, cost from tt_predefined_expenses". + " where group_id = $group_id and org_id = $org_id"; + $res = $mdb2->query($sql); + $result = array(); + if (!is_a($res, 'PEAR_Error')) { + $decimal_mark = $user->getDecimalMark(); + $replaceDecimalMark = ('.' != $decimal_mark); + + while ($val = $res->fetchRow()) { + if ($replaceDecimalMark) + $val['cost'] = str_replace('.', $decimal_mark, $val['cost']); + $result[] = $val; + } + return $result; + } + return false; + } } diff --git a/WEB-INF/lib/ttPredefinedExpenseHelper.class.php b/WEB-INF/lib/ttPredefinedExpenseHelper.class.php index 16dff284..670e061c 100644 --- a/WEB-INF/lib/ttPredefinedExpenseHelper.class.php +++ b/WEB-INF/lib/ttPredefinedExpenseHelper.class.php @@ -67,18 +67,17 @@ class ttPredefinedExpenseHelper { } // insert function inserts a new predefined expense into database. - static function insert($fields) - { + static function insert($fields) { global $user; - $mdb2 = getConnection(); $group_id = $user->getGroup(); $org_id = $user->org_id; + $name = $fields['name']; $cost = $fields['cost']; - if ('.' != $user->decimal_mark) - $cost = str_replace($user->decimal_mark, '.', $cost); + if ('.' != $user->getDecimalMark()) + $cost = str_replace($user->getDecimalMark, '.', $cost); $sql = "insert into tt_predefined_expenses (group_id, org_id, name, cost)". " values ($group_id, $org_id, ".$mdb2->quote($name).", ".$mdb2->quote($cost).")"; diff --git a/WEB-INF/lib/ttTeamHelper.class.php b/WEB-INF/lib/ttTeamHelper.class.php index e64bd672..1e626313 100644 --- a/WEB-INF/lib/ttTeamHelper.class.php +++ b/WEB-INF/lib/ttTeamHelper.class.php @@ -540,28 +540,6 @@ class ttTeamHelper { return false; } - // getPredefinedExpenses - obtains predefined expenses for a group. - static function getPredefinedExpenses($group_id) { - global $user; - $replaceDecimalMark = ('.' != $user->decimal_mark); - - $mdb2 = getConnection(); - - $result = array(); - $sql = "select id, name, cost from tt_predefined_expenses where group_id = $group_id"; - $res = $mdb2->query($sql); - $result = array(); - if (!is_a($res, 'PEAR_Error')) { - while ($val = $res->fetchRow()) { - if ($replaceDecimalMark) - $val['cost'] = str_replace('.', $user->decimal_mark, $val['cost']); - $result[] = $val; - } - return $result; - } - return false; - } - // getNotifications - obtains notification descriptions for a group. static function getNotifications($group_id) { $mdb2 = getConnection(); diff --git a/WEB-INF/templates/expense_delete.tpl b/WEB-INF/templates/expense_delete.tpl index 52462c8d..e2c1b671 100644 --- a/WEB-INF/templates/expense_delete.tpl +++ b/WEB-INF/templates/expense_delete.tpl @@ -8,7 +8,7 @@ {$i18n.label.client} {/if} -{if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)} +{if $show_project} {$i18n.label.project} {/if} {$i18n.label.item} @@ -18,7 +18,7 @@ {if $user->isPluginEnabled('cl')} {$expense_item.client_name|escape} {/if} -{if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)} +{if $show_project} {$expense_item.project_name|escape} {/if} {$expense_item.name|escape} diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 7654f5d8..e74a6a5e 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
- {/if} -{if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)} +{if $show_project} {/if} @@ -18,7 +18,7 @@ {if $user->isPluginEnabled('cl')} {/if} -{if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)} +{if $show_project} {/if} diff --git a/expense_delete.php b/expense_delete.php index d5eccf79..c7031769 100644 --- a/expense_delete.php +++ b/expense_delete.php @@ -48,6 +48,7 @@ if (!$expense_item || $expense_item['invoice_id']) { header('Location: access_denied.php'); exit(); } +// End of access checks. if ($request->isPost()) { if ($request->getParameter('delete_button')) { // Delete button pressed. @@ -77,8 +78,11 @@ $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_id)); $form->addInput(array('type'=>'submit','name'=>'delete_button','value'=>$i18n->get('label.delete'))); $form->addInput(array('type'=>'submit','name'=>'cancel_button','value'=>$i18n->get('button.cancel'))); -$smarty->assign('expense_item', $expense_item); +$show_project = MODE_PROJECTS == $user->getTrackingMode() || MODE_PROJECTS_AND_TASKS == $user->getTrackingMode(); + $smarty->assign('forms', array($form->getName() => $form->toArray())); +$smarty->assign('expense_item', $expense_item); +$smarty->assign('show_project', $show_project); $smarty->assign('title', $i18n->get('title.delete_expense')); $smarty->assign('content_page_name', 'expense_delete.tpl'); $smarty->display('index.tpl'); diff --git a/expense_edit.php b/expense_edit.php index dd4a133b..c42bddc8 100644 --- a/expense_edit.php +++ b/expense_edit.php @@ -28,7 +28,6 @@ require_once('initialize.php'); import('form.Form'); -import('ttTeamHelper'); import('ttGroupHelper'); import('DateAndTime'); import('ttExpenseHelper'); @@ -50,9 +49,12 @@ if (!$expense_item || $expense_item['invoice_id']) { header('Location: access_denied.php'); exit(); } +// End of access checks. $item_date = new DateAndTime(DB_DATEFORMAT, $expense_item['date']); $confirm_save = $user->getConfigOption('confirm_save'); +$trackingMode = $user->getTrackingMode(); +$show_project = MODE_PROJECTS == $trackingMode || MODE_PROJECTS_AND_TASKS == $trackingMode; // Initialize variables. $cl_date = $cl_client = $cl_project = $cl_item_name = $cl_cost = null; @@ -65,7 +67,7 @@ if ($request->isPost()) { if ($user->isPluginEnabled('ps')) $cl_paid = $request->getParameter('paid'); } else { - $cl_date = $item_date->toString($user->date_format); + $cl_date = $item_date->toString($user->getDateFormat()); $cl_client = $expense_item['client_id']; $cl_project = $expense_item['project_id']; $cl_item_name = $expense_item['name']; @@ -77,7 +79,7 @@ if ($request->isPost()) { $form = new Form('expenseItemForm'); // Dropdown for clients in MODE_TIME. Use all active clients. -if (MODE_TIME == $user->tracking_mode && $user->isPluginEnabled('cl')) { +if (MODE_TIME == $trackingMode && $user->isPluginEnabled('cl')) { $active_clients = ttGroupHelper::getActiveClients(true); $form->addInput(array('type'=>'combobox', 'onchange'=>'fillProjectDropdown(this.value);', @@ -90,7 +92,7 @@ if (MODE_TIME == $user->tracking_mode && $user->isPluginEnabled('cl')) { // Note: in other modes the client list is filtered to relevant clients only. See below. } -if (MODE_PROJECTS == $user->tracking_mode || MODE_PROJECTS_AND_TASKS == $user->tracking_mode) { +if ($show_project) { // Dropdown for projects assigned to user. $project_list = $user->getAssignedProjects(); $form->addInput(array('type'=>'combobox', @@ -129,7 +131,7 @@ if (MODE_PROJECTS == $user->tracking_mode || MODE_PROJECTS_AND_TASKS == $user->t } } // If predefined expenses are configured, add controls to select an expense and quantity. -$predefined_expenses = ttTeamHelper::getPredefinedExpenses($user->group_id); +$predefined_expenses = ttGroupHelper::getPredefinedExpenses(); if ($predefined_expenses) { $form->addInput(array('type'=>'combobox', 'onchange'=>'recalculateCost();', @@ -159,7 +161,7 @@ if ($request->isPost()) { // Validate user input. if ($user->isPluginEnabled('cl') && $user->isPluginEnabled('cm') && !$cl_client) $err->add($i18n->get('error.client')); - if (MODE_PROJECTS == $user->tracking_mode || MODE_PROJECTS_AND_TASKS == $user->tracking_mode) { + if (MODE_PROJECTS == $trackingMode || MODE_PROJECTS_AND_TASKS == $trackingMode) { if (!$cl_project) $err->add($i18n->get('error.project')); } if (!ttValidString($cl_item_name)) $err->add($i18n->get('error.field'), $i18n->get('label.item')); diff --git a/expenses.php b/expenses.php index 1c70a5a3..882e520b 100644 --- a/expenses.php +++ b/expenses.php @@ -29,7 +29,6 @@ require_once('initialize.php'); import('form.Form'); import('ttUserHelper'); -import('ttTeamHelper'); import('ttGroupHelper'); import('DateAndTime'); import('ttExpenseHelper'); @@ -145,7 +144,7 @@ if (MODE_PROJECTS == $user->tracking_mode || MODE_PROJECTS_AND_TASKS == $user->t } } // If predefined expenses are configured, add controls to select an expense and quantity. -$predefined_expenses = ttTeamHelper::getPredefinedExpenses($user->group_id); +$predefined_expenses = ttGroupHelper::getPredefinedExpenses(); if ($predefined_expenses) { $form->addInput(array('type'=>'combobox', 'onchange'=>'recalculateCost();', diff --git a/mobile/expense_delete.php b/mobile/expense_delete.php index c33f5232..3bdc179d 100644 --- a/mobile/expense_delete.php +++ b/mobile/expense_delete.php @@ -48,6 +48,7 @@ if (!$expense_item || $expense_item['invoice_id']) { header('Location: access_denied.php'); exit(); } +// End of access checks. if ($request->isPost()) { if ($request->getParameter('delete_button')) { // Delete button pressed. @@ -77,8 +78,11 @@ $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_id)); $form->addInput(array('type'=>'submit','name'=>'delete_button','value'=>$i18n->get('label.delete'))); $form->addInput(array('type'=>'submit','name'=>'cancel_button','value'=>$i18n->get('button.cancel'))); -$smarty->assign('expense_item', $expense_item); +$show_project = MODE_PROJECTS == $user->getTrackingMode() || MODE_PROJECTS_AND_TASKS == $user->getTrackingMode(); + $smarty->assign('forms', array($form->getName() => $form->toArray())); +$smarty->assign('expense_item', $expense_item); +$smarty->assign('show_project', $show_project); $smarty->assign('title', $i18n->get('title.delete_expense')); $smarty->assign('content_page_name', 'mobile/expense_delete.tpl'); $smarty->display('mobile/index.tpl'); diff --git a/mobile/expense_edit.php b/mobile/expense_edit.php index 7938a4f1..0f657973 100644 --- a/mobile/expense_edit.php +++ b/mobile/expense_edit.php @@ -28,7 +28,6 @@ require_once('../initialize.php'); import('form.Form'); -import('ttTeamHelper'); import('ttGroupHelper'); import('DateAndTime'); import('ttExpenseHelper'); @@ -126,7 +125,7 @@ if (MODE_PROJECTS == $user->tracking_mode || MODE_PROJECTS_AND_TASKS == $user->t } } // If predefined expenses are configured, add controls to select an expense and quantity. -$predefined_expenses = ttTeamHelper::getPredefinedExpenses($user->group_id); +$predefined_expenses = ttGroupHelper::getPredefinedExpenses(); if ($predefined_expenses) { $form->addInput(array('type'=>'combobox', 'onchange'=>'recalculateCost();', diff --git a/mobile/expenses.php b/mobile/expenses.php index 15f914b2..84d29738 100644 --- a/mobile/expenses.php +++ b/mobile/expenses.php @@ -29,7 +29,6 @@ require_once('../initialize.php'); import('form.Form'); import('ttUserHelper'); -import('ttTeamHelper'); import('ttGroupHelper'); import('DateAndTime'); import('ttExpenseHelper'); @@ -149,7 +148,7 @@ if (MODE_PROJECTS == $user->tracking_mode || MODE_PROJECTS_AND_TASKS == $user->t } } // If predefined expenses are configured, add controls to select an expense and quantity. -$predefined_expenses = ttTeamHelper::getPredefinedExpenses($user->group_id); +$predefined_expenses = ttGroupHelper::getPredefinedExpenses(); if ($predefined_expenses) { $form->addInput(array('type'=>'combobox', 'onchange'=>'recalculateCost();', diff --git a/predefined_expenses.php b/predefined_expenses.php index 88ac44d7..99c2c899 100644 --- a/predefined_expenses.php +++ b/predefined_expenses.php @@ -28,7 +28,7 @@ require_once('initialize.php'); import('form.Form'); -import('ttTeamHelper'); +import('ttGroupHelper'); // Access checks. if (!ttAccessAllowed('manage_advanced_settings')) { @@ -50,7 +50,7 @@ if ($request->isPost()) { } } else { $form->addInput(array('type'=>'submit','name'=>'btn_add','value'=>$i18n->get('button.add'))); - $predefinedExpenses = ttTeamHelper::getPredefinedExpenses($user->group_id); + $predefinedExpenses = ttGroupHelper::getPredefinedExpenses(); } $smarty->assign('forms', array($form->getName()=>$form->toArray())); -- 2.20.1
 Anuko Time Tracker 1.18.29.4584 | Copyright © Anuko | +  Anuko Time Tracker 1.18.29.4585 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/WEB-INF/templates/mobile/expense_delete.tpl b/WEB-INF/templates/mobile/expense_delete.tpl index bfd6dbc1..cbd75aed 100644 --- a/WEB-INF/templates/mobile/expense_delete.tpl +++ b/WEB-INF/templates/mobile/expense_delete.tpl @@ -8,7 +8,7 @@ {$i18n.label.client}{$i18n.label.project}{$i18n.label.item}{$expense_item.client_name|escape}{$expense_item.project_name|escape}{$expense_item.name|escape}