From e5486346ac0574517a4fd118f03616ec455df9a9 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Fri, 22 Feb 2019 22:13:15 +0000 Subject: [PATCH] Implemented timesheet approval in initial form. --- WEB-INF/lib/ttTimesheetHelper.class.php | 46 +++++++++++++++++++++++++ WEB-INF/templates/footer.tpl | 2 +- WEB-INF/templates/timesheet_view.tpl | 4 ++- timesheet_view.php | 29 +++++++++++++++- 4 files changed, 78 insertions(+), 3 deletions(-) diff --git a/WEB-INF/lib/ttTimesheetHelper.class.php b/WEB-INF/lib/ttTimesheetHelper.class.php index df1e4e48..21e75a96 100644 --- a/WEB-INF/lib/ttTimesheetHelper.class.php +++ b/WEB-INF/lib/ttTimesheetHelper.class.php @@ -369,4 +369,50 @@ class ttTimesheetHelper { return true; } + + // approveTimesheet marks a timesheet as approved and sends an email to submitter. + static function approveTimesheet($fields) { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + // First, mark a timesheet as approved. + // Even if mail part below does not work, this will get us a functioning workflow + // (without email notifications). + $timesheet_id = $fields['timesheet_id']; + $manager_comment = $fields['comment']; + + $sql = "update tt_timesheets set approval_status = 1, manager_comment = ".$mdb2->quote($manager_comment). + " where id = $timesheet_id and submit_status = 1 and group_id = $group_id and org_id = $org_id"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) return false; + + // TODO: send email to submitter here... + return true; + } + + // disapproveTimesheet marks a timesheet as approved and sends an email to submitter. + static function disapproveTimesheet($fields) { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + // First, mark a timesheet as disapproved. + // Even if mail part below does not work, this will get us a functioning workflow + // (without email notifications). + $timesheet_id = $fields['timesheet_id']; + $manager_comment = $fields['comment']; + + $sql = "update tt_timesheets set approval_status = 0, manager_comment = ".$mdb2->quote($manager_comment). + " where id = $timesheet_id and submit_status = 1 and group_id = $group_id and org_id = $org_id"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) return false; + + // TODO: send email to submitter here... + return true; + } } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 71d49f2e..024e05d3 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
- diff --git a/timesheet_view.php b/timesheet_view.php index 0e9a7ea9..70ab3357 100644 --- a/timesheet_view.php +++ b/timesheet_view.php @@ -48,6 +48,10 @@ if (!$timesheet) { // TODO: if this is a timeheet submit, validate approver id, too. // End of access checks. +if ($request->isPost()) { + $cl_comment = trim($request->getParameter('comment')); +} + $options = ttTimesheetHelper::getReportOptions($timesheet); $subtotals = ttReportHelper::getSubtotals($options); $totals = ttReportHelper::getTotals($options); @@ -57,7 +61,7 @@ $notClient = !$user->isClient(); $showSubmit = $notClient && !$timesheet['submit_status']; if ($showSubmit) $approvers = ttTimesheetHelper::getApprovers($timesheet['user_id']); $canApprove = $user->can('approve_timesheets') || $user_>can('approve_all_timesheets'); -$showApprove = $notClient && $timesheet['submit_status'] && !$timesheet['approval_status']; +$showApprove = $notClient && $timesheet['submit_status'] && $timesheet['approval_status'] == null; // Add a form with controls. $form = new Form('timesheetForm'); @@ -75,6 +79,7 @@ if ($showSubmit) { } if ($showApprove) { + $form->addInput(array('type'=>'textarea','name'=>'comment','maxlength'=>'250','style'=>'width: 300px; height: 60px;')); $form->addInput(array('type'=>'submit','name'=>'btn_approve','value'=>$i18n->get('button.approve'))); $form->addInput(array('type'=>'submit','name'=>'btn_disapprove','value'=>$i18n->get('button.disapprove'))); } @@ -91,6 +96,28 @@ if ($request->isPost()) { } else $err->add($i18n->get('error.db')); } + + if ($request->getParameter('btn_approve')) { + $fields = array('timesheet_id' => $timesheet['id'], + 'comment' => $cl_comment); + if (ttTimesheetHelper::approveTimesheet($fields)) { + // Redirect to self. + header('Location: timesheet_view.php?id='.$timesheet['id']); + exit(); + } else + $err->add($i18n->get('error.db')); + } + + if ($request->getParameter('btn_disapprove')) { + $fields = array('timesheet_id' => $timesheet['id'], + 'comment' => $cl_comment); + if (ttTimesheetHelper::disapproveTimesheet($fields)) { + // Redirect to self. + header('Location: timesheet_view.php?id='.$timesheet['id']); + exit(); + } else + $err->add($i18n->get('error.db')); + } } $smarty->assign('not_client', $notClient); -- 2.20.1
 Anuko Time Tracker 1.18.37.4753 | Copyright © Anuko | +  Anuko Time Tracker 1.18.37.4754 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/WEB-INF/templates/timesheet_view.tpl b/WEB-INF/templates/timesheet_view.tpl index 17114439..97591fe0 100644 --- a/WEB-INF/templates/timesheet_view.tpl +++ b/WEB-INF/templates/timesheet_view.tpl @@ -66,7 +66,9 @@
- + + +
{$forms.timesheetForm.btn_approve.control} {$forms.timesheetForm.btn_disapprove.control}
{$i18n.label.comment}:
{$forms.timesheetForm.comment.control}
{$forms.timesheetForm.btn_approve.control} {$forms.timesheetForm.btn_disapprove.control}