From: Nik Okuntseff Date: Mon, 18 Feb 2019 16:23:41 +0000 (+0000) Subject: Implemented deleting a timesheet. X-Git-Tag: timetracker_1.19-1~317 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=a64a8d017c37bec34585e0c345a0c139ac3b43a0;p=timetracker.git Implemented deleting a timesheet. --- diff --git a/WEB-INF/lib/ttTimesheetHelper.class.php b/WEB-INF/lib/ttTimesheetHelper.class.php index f7cae676..df654e07 100644 --- a/WEB-INF/lib/ttTimesheetHelper.class.php +++ b/WEB-INF/lib/ttTimesheetHelper.class.php @@ -79,8 +79,8 @@ class ttTimesheetHelper { return $last_id; } - // The getTimesheets obtains timesheets for user. - static function getTimesheets($user_id) + // The getActiveTimesheets obtains active timesheets for a user. + static function getActiveTimesheets($user_id) { global $user; $mdb2 = getConnection(); @@ -94,7 +94,7 @@ class ttTimesheetHelper { 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 from tt_timesheets ts". + $sql = "select ts.id, ts.name, ts.client_id, c.name as client_name, ts.submit_status, ts.approval_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"; @@ -110,4 +110,83 @@ class ttTimesheetHelper { } return $result; } + + // The getInactiveTimesheets obtains inactive timesheets for a user. + static function getInactiveTimesheets($user_id) + { + global $user; + $mdb2 = getConnection(); + + $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.approval_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"; + $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; + } + } + return $result; + } + + // getTimesheet - obtains timesheet data from the database. + static function getTimesheet($timesheet_id) { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + if ($user->isClient()) $client_part = "and client_id = $user->client_id"; + + $sql = "select * from tt_timesheets". + " where id = $timesheet_id and group_id = $group_id and org_id = $org_id $client_part and status = 1"; + $res = $mdb2->query($sql); + if (!is_a($res, 'PEAR_Error')) { + if ($val = $res->fetchRow()) + return $val; + } + return false; + } + + // delete - deletes timesheet from the database. + static function delete($timesheet_id) { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + // Handle time records. + $sql = "update tt_log set timesheet_id = null". + " where timesheet_id = $timesheet_id and group_id = $group_id and org_id = $org_id"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) return false; + + // Handle expense items. + $sql = "update tt_expense_items set timesheet_id = null". + " where timesheet_id = $timesheet_id and group_id = $group_id and org_id = $org_id"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) return false; + + // Delete timesheet. + $sql = "update tt_timesheets set status = null". + " where id = $timesheet_id and group_id = $group_id and org_id = $org_id"; + $affected = $mdb2->exec($sql); + return (!is_a($affected, 'PEAR_Error')); + } } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index a91fdab4..5e19420d 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.37.4735 | Copyright © Anuko | +  Anuko Time Tracker 1.18.37.4736 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/WEB-INF/templates/timesheet_delete.tpl b/WEB-INF/templates/timesheet_delete.tpl new file mode 100644 index 00000000..87928052 --- /dev/null +++ b/WEB-INF/templates/timesheet_delete.tpl @@ -0,0 +1,18 @@ +{$forms.timesheetDeleteForm.open} + + + + +
+ + + + + + + + + +
{$timesheet_to_delete|escape}
 
{$forms.timesheetDeleteForm.btn_delete.control}  {$forms.timesheetDeleteForm.btn_cancel.control}
+
+{$forms.timesheetDeleteForm.close} diff --git a/WEB-INF/templates/timesheets.tpl b/WEB-INF/templates/timesheets.tpl index 796f2720..0ba8fd7c 100644 --- a/WEB-INF/templates/timesheets.tpl +++ b/WEB-INF/templates/timesheets.tpl @@ -5,29 +5,46 @@
-{if $user->can('manage_invoices') || $user->can('view_own_invoices')} + + {if $inactive_timesheets} + + {/if} - {if $user->isPluginEnabled('cl')} + {if $show_client} {/if} - - + {if $show_submit_status} + + {/if} + {if $show_approval_status} + + {/if} + + - {foreach $timesheets as $timesheet} + {foreach $active_timesheets as $timesheet} + {if $show_client} - - {if $user->isPluginEnabled('ps')} - {/if} - + {if $show_submit_status} + + {/if} + {if $show_approval_status} + + {/if} + + + + {if !$user->isClient()} - + + {/if} {/foreach} @@ -38,7 +55,6 @@
{$i18n.form.timesheets.hint}
 
{$i18n.form.timesheets.active_timesheets}
{$i18n.label.thing_name}{$i18n.label.client}{$i18n.label.submitted}{$i18n.label.approved}{$i18n.label.submitted}{$i18n.label.approved}{$i18n.label.view}{$i18n.label.edit}{$i18n.label.delete}
{$timesheet.name|escape}{$timesheet.client_name|escape}{$invoice.date}{if $invoice.paid}{$i18n.label.yes}{else}{$i18n.label.no}{/if}{$i18n.label.view}{if $timesheet.submit_status}{$i18n.label.yes}{else}{$i18n.label.no}{/if}{if $timesheet.approval_status}{$i18n.label.yes}{else}{$i18n.label.no}{/if}{$i18n.label.view}{$i18n.label.delete}{$i18n.label.edit}{$i18n.label.delete}

{/if} -{/if}
diff --git a/invoice_delete.php b/invoice_delete.php index ffdcf2c1..89ea372a 100644 --- a/invoice_delete.php +++ b/invoice_delete.php @@ -60,12 +60,9 @@ $form->addInput(array('type'=>'submit','name'=>'btn_cancel','value'=>$i18n->get( if ($request->isPost()) { if ($request->getParameter('btn_delete')) { - if (ttInvoiceHelper::getInvoice($cl_invoice_id)) { - if (ttInvoiceHelper::delete($cl_invoice_id, $request->getParameter('delete_invoice_entries'))) { - header('Location: invoices.php'); - exit(); - } else - $err->add($i18n->get('error.db')); + if (ttInvoiceHelper::delete($cl_invoice_id, $request->getParameter('delete_invoice_entries'))) { + header('Location: invoices.php'); + exit(); } else $err->add($i18n->get('error.db')); } elseif ($request->getParameter('btn_cancel')) { diff --git a/timesheet_delete.php b/timesheet_delete.php new file mode 100644 index 00000000..e4bf453c --- /dev/null +++ b/timesheet_delete.php @@ -0,0 +1,75 @@ +isPluginEnabled('ts')) { + header('Location: feature_disabled.php'); + exit(); +} +$cl_timesheet_id = (int)$request->getParameter('id'); +$timesheet = ttTimesheetHelper::getTimesheet($cl_timesheet_id); +if (!$timesheet) { + header('Location: access_denied.php'); + exit(); +} +// End of access checks. + +$timesheet_to_delete = $timesheet['name']; + +$form = new Form('timesheetDeleteForm'); +$form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_timesheet_id)); +$form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get('label.delete'))); +$form->addInput(array('type'=>'submit','name'=>'btn_cancel','value'=>$i18n->get('button.cancel'))); + +if ($request->isPost()) { + if ($request->getParameter('btn_delete')) { + if (ttTimesheetHelper::delete($cl_timesheet_id)) { + header('Location: timesheets.php'); + exit(); + } else + $err->add($i18n->get('error.db')); + } elseif ($request->getParameter('btn_cancel')) { + header('Location: timesheets.php'); + exit(); + } +} // isPost + +$smarty->assign('timesheet_to_delete', $timesheet_to_delete); +$smarty->assign('forms', array($form->getName()=>$form->toArray())); +$smarty->assign('onload', 'onLoad="document.invoiceDeleteForm.btn_cancel.focus()"'); +$smarty->assign('title', $i18n->get('title.delete_timesheet')); +$smarty->assign('content_page_name', 'timesheet_delete.tpl'); +$smarty->display('index.tpl'); diff --git a/timesheets.php b/timesheets.php index 4a4eb66f..191f7492 100644 --- a/timesheets.php +++ b/timesheets.php @@ -46,9 +46,20 @@ if (!$user->isPluginEnabled('ts')) { } // End of access checks. -$timesheets = ttTimesheetHelper::getTimesheets($user->getUser()); +// TODO: determine user properly, using a dropdown. +$user_id = $user->getUser(); + +// TODO: fix this for client access. +$active_timesheets = ttTimesheetHelper::getActiveTimesheets($user_id); +$inactive_timesheets = ttTimesheetHelper::getInactiveTimesheets($user_id); +$show_client = $user->isPluginEnabled('cl') && !$user->isClient(); + +$smarty->assign('active_timesheets', $active_timesheets); +$smarty->assign('inactive_timesheets', $inactive_timesheets); +$smarty->assign('show_client', $show_client); +$smarty->assign('show_submit_status', !$user->isClient()); +$smarty->assign('show_approval_status', !$user->isClient()); -$smarty->assign('timesheets', $timesheets); $smarty->assign('title', $i18n->get('title.timesheets')); $smarty->assign('content_page_name', 'timesheets.tpl'); $smarty->display('index.tpl');