From d40f3b7898583d430d651cc5210994cf55dd5b13 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Sat, 2 Mar 2019 16:05:40 +0000 Subject: [PATCH] More refactoring on timesheet code. --- WEB-INF/lib/ttTimesheetHelper.class.php | 34 ++++++++----------------- WEB-INF/templates/footer.tpl | 2 +- timesheet_view.php | 1 + timesheets.php | 4 +-- 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/WEB-INF/lib/ttTimesheetHelper.class.php b/WEB-INF/lib/ttTimesheetHelper.class.php index e2af4e72..743477b2 100644 --- a/WEB-INF/lib/ttTimesheetHelper.class.php +++ b/WEB-INF/lib/ttTimesheetHelper.class.php @@ -83,7 +83,7 @@ class ttTimesheetHelper { $last_id = $mdb2->lastInsertID('tt_timesheets', 'id'); - // Associate time items with timesheet. + // Associate tt_log items with timesheet. if (isset($fields['client'])) $client_id = (int) $fields['client_id']; if (isset($fields['project_id'])) $project_id = (int) $fields['project_id']; // sql parts. @@ -102,31 +102,25 @@ class ttTimesheetHelper { } // The getActiveTimesheets obtains active timesheets for a user. - static function getActiveTimesheets($user_id) + static function getActiveTimesheets() { global $user; $mdb2 = getConnection(); + $user_id = $user->getUser(); $group_id = $user->getGroup(); $org_id = $user->org_id; - // $addPaidStatus = $user->isPluginEnabled('ps'); $result = array(); - - if ($user->isClient()) - $client_part = "and ts.client_id = $user->client_id"; - - $sql = "select ts.id, ts.name, ts.client_id, c.name as client_name, ts.submit_status, ts.approve_status from tt_timesheets ts". + $sql = "select ts.id, ts.name, ts.client_id, c.name as client_name,". + " ts.submit_status, ts.approve_status from tt_timesheets ts". " left join tt_clients c on (c.id = ts.client_id)". " where ts.status = 1 and ts.group_id = $group_id and ts.org_id = $org_id and ts.user_id = $user_id". - " $client_part order by ts.name"; + " order by ts.name"; $res = $mdb2->query($sql); $result = array(); if (!is_a($res, 'PEAR_Error')) { - $dt = new DateAndTime(DB_DATEFORMAT); while ($val = $res->fetchRow()) { - //if ($addPaidStatus) - // $val['paid'] = ttTimesheetHelper::isPaid($val['id']); $result[] = $val; } } @@ -134,31 +128,25 @@ class ttTimesheetHelper { } // The getInactiveTimesheets obtains inactive timesheets for a user. - static function getInactiveTimesheets($user_id) + static function getInactiveTimesheets() { global $user; $mdb2 = getConnection(); + $user_id = $user->getUser(); $group_id = $user->getGroup(); $org_id = $user->org_id; - // $addPaidStatus = $user->isPluginEnabled('ps'); $result = array(); - - if ($user->isClient()) - $client_part = "and ts.client_id = $user->client_id"; - - $sql = "select ts.id, ts.name, ts.client_id, c.name as client_name, ts.submit_status, ts.approve_status from tt_timesheets ts". + $sql = "select ts.id, ts.name, ts.client_id, c.name as client_name,". + " ts.submit_status, ts.approve_status from tt_timesheets ts". " left join tt_clients c on (c.id = ts.client_id)". " where ts.status = 0 and ts.group_id = $group_id and ts.org_id = $org_id and ts.user_id = $user_id". - " $client_part order by ts.name"; + " order by ts.name"; $res = $mdb2->query($sql); $result = array(); if (!is_a($res, 'PEAR_Error')) { - $dt = new DateAndTime(DB_DATEFORMAT); while ($val = $res->fetchRow()) { - //if ($addPaidStatus) - // $val['paid'] = ttTimesheetHelper::isPaid($val['id']); $result[] = $val; } } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index c801c765..e98faf23 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.50.4807 | Copyright © Anuko | +  Anuko Time Tracker 1.18.50.4808 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/timesheet_view.php b/timesheet_view.php index 57eff61c..e6368a39 100644 --- a/timesheet_view.php +++ b/timesheet_view.php @@ -28,6 +28,7 @@ require_once('initialize.php'); import('ttTimesheetHelper'); +import('ttReportHelper'); // Access checks. if (!(ttAccessAllowed('track_own_time') || ttAccessAllowed('track_time'))) { diff --git a/timesheets.php b/timesheets.php index 650575e6..b3b47772 100644 --- a/timesheets.php +++ b/timesheets.php @@ -90,8 +90,8 @@ if ($user->can('track_time')) { } } -$active_timesheets = ttTimesheetHelper::getActiveTimesheets($user_id); -$inactive_timesheets = ttTimesheetHelper::getInactiveTimesheets($user_id); +$active_timesheets = ttTimesheetHelper::getActiveTimesheets(); +$inactive_timesheets = ttTimesheetHelper::getInactiveTimesheets(); $showClient = $user->isPluginEnabled('cl'); -- 2.20.1