From: Nik Okuntseff Date: Fri, 22 Feb 2019 16:16:25 +0000 (+0000) Subject: Started to work on timesheet approval workflow. X-Git-Tag: timetracker_1.19-1~296 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=c7d73ed8f6e2deade801bedaeb3af934ba69bf88;p=timetracker.git Started to work on timesheet approval workflow. --- diff --git a/WEB-INF/lib/ttTimesheetHelper.class.php b/WEB-INF/lib/ttTimesheetHelper.class.php index 07f02f86..0d4556bc 100644 --- a/WEB-INF/lib/ttTimesheetHelper.class.php +++ b/WEB-INF/lib/ttTimesheetHelper.class.php @@ -321,4 +321,29 @@ class ttTimesheetHelper { } return $options; } + + // getApprovers obtains a list of users who can approve a timesheet for a given user + // and also have an email to receive a notification about it. + static function getApprovers($user_id) { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $approvers = array(); + $rank = ttUserHelper::getUserRank($user_id); + $sql = "select u.id, u.name, u.email". + " from tt_users u". + " left join tt_roles r on (r.id = u.role_id)". + " where u.status = 1 and u.email is not null". + " and (r.rights like '%approve_all_timesheets%' or (r.rank > $rank and r.rights like '%approve_timesheets%'))"; + $res = $mdb2->query($sql); + if (!is_a($res, 'PEAR_Error')) { + while ($val = $res->fetchRow()) { + $approvers[] = $val; + } + } + return $approvers; + } } diff --git a/WEB-INF/lib/ttUser.class.php b/WEB-INF/lib/ttUser.class.php index 36f9163f..28eeebcf 100644 --- a/WEB-INF/lib/ttUser.class.php +++ b/WEB-INF/lib/ttUser.class.php @@ -592,7 +592,7 @@ class ttUser { return false; // So far, so good. Check user now. - $options = array('group_id'=>$group_id,'status'=>ACTIVE,'max_rank'=>MAX_RANK); + $options = array('status'=>ACTIVE,'max_rank'=>MAX_RANK); $users = $this->getUsers($options); foreach($users as $one_user) { if ($one_user['id'] == $this->behalf_id) diff --git a/WEB-INF/lib/ttUserHelper.class.php b/WEB-INF/lib/ttUserHelper.class.php index d0a09ced..17ef08c2 100644 --- a/WEB-INF/lib/ttUserHelper.class.php +++ b/WEB-INF/lib/ttUserHelper.class.php @@ -404,4 +404,21 @@ class ttUserHelper { return false; } + + // getUserRank - obtains a rank for a given user. + static function getUserRank($user_id) { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $sql = "select r.rank from tt_users u". + " left join tt_roles r on (u.role_id = r.id)". + " where u.id = $user_id and u.group_id = $group_id and u.org_id = $org_id"; + $res = $mdb2->query($sql); + if (is_a($res, 'PEAR_Error')) return 0; + $val = $res->fetchRow(); + return $val['rank']; + } } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 86ccb33f..a84e3246 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.37.4751 | Copyright © Anuko | +  Anuko Time Tracker 1.18.37.4752 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/timesheet_view.php b/timesheet_view.php index 80b3b77a..bd97a52a 100644 --- a/timesheet_view.php +++ b/timesheet_view.php @@ -52,6 +52,9 @@ $subtotals = ttReportHelper::getSubtotals($options); $totals = ttReportHelper::getTotals($options); $notClient = !$user->isClient(); +// Determine managers we can submit this timesheet for approval to. +$approvers = ttTimesheetHelper::getApprovers($timesheet['user_id']); + $smarty->assign('not_client', $notClient); $smarty->assign('group_by_header', ttReportHelper::makeGroupByHeader($options)); $smarty->assign('timesheet', $timesheet);