From: Nik Okuntseff Date: Thu, 21 Feb 2019 17:11:44 +0000 (+0000) Subject: Implemented timesheet view. X-Git-Tag: timetracker_1.19-1~299 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=bc7836c64252d104495878af3c005210cb977072;p=timetracker.git Implemented timesheet view. --- diff --git a/WEB-INF/lib/ttReportHelper.class.php b/WEB-INF/lib/ttReportHelper.class.php index c3656ad6..1f537bbb 100644 --- a/WEB-INF/lib/ttReportHelper.class.php +++ b/WEB-INF/lib/ttReportHelper.class.php @@ -43,6 +43,12 @@ class ttReportHelper { $group_id = $user->getGroup(); $org_id = $user->org_id; + // A shortcut for timesheets. + if ($options['timesheet_id']) { + $where = " where l.timesheet_id = ".$options['timesheet_id']." and l.group_id = $group_id and l.org_id = $org_id"; + return $where; + } + // Prepare dropdown parts. $dropdown_parts = ''; if ($options['client_id']) @@ -89,6 +95,12 @@ class ttReportHelper { $group_id = $user->getGroup(); $org_id = $user->org_id; + // A shortcut for timesheets. + if ($options['timesheet_id']) { + $where = " where ei.timesheet_id = ".$options['timesheet_id']." and ei.group_id = $group_id and ei.org_id = $org_id"; + return $where; + } + // Prepare dropdown parts. $dropdown_parts = ''; if ($options['client_id']) diff --git a/WEB-INF/lib/ttTimesheetHelper.class.php b/WEB-INF/lib/ttTimesheetHelper.class.php index 49808359..94b9beff 100644 --- a/WEB-INF/lib/ttTimesheetHelper.class.php +++ b/WEB-INF/lib/ttTimesheetHelper.class.php @@ -214,7 +214,8 @@ class ttTimesheetHelper { if ($user->isClient()) $client_part = "and ts.client_id = $user->client_id"; - $sql = "select ts.id, ts.user_id, u.name as user_name, ts.client_id, c.name as client_name, ts.name from tt_timesheets ts". + $sql = "select ts.id, ts.user_id, u.name as user_name, ts.client_id, c.name as client_name,". + " ts.name, ts.submitter_comment from tt_timesheets ts". " left join tt_users u on (u.id = ts.user_id)". " left join tt_clients c on (c.id = ts.client_id)". " where ts.id = $timesheet_id and ts.group_id = $group_id and ts.org_id = $org_id $client_part and ts.status is not null"; @@ -296,4 +297,28 @@ class ttTimesheetHelper { return true; } + + // getReportOptions prepares $options array to be used with ttReportHelper + // to obtain items for timesheet view. + static function getReportOptions($timesheet) { + global $user; + $group_by_client = $user->isPluginEnabled('cl') && !$timesheet['client_id']; + $trackingMode = $user->getTrackingMode(); + $group_by_project = MODE_PROJECTS == $trackingMode || MODE_PROJECTS_AND_TASKS == $trackingMode; + + $options['timesheet_id'] = $timesheet['id']; + $options['client_id'] = $timesheet['client_id']; + $options['users'] = $timesheet['user_id']; + $options['show_durarion'] = 1; + $options['show_cost'] = 1; // To include expenses. + $options['show_totals_only'] = 1; + $options['group_by1'] = 'date'; + if ($group_by_client || $group_by_project) { + $options['group_by2'] = $group_by_client ? 'client' : 'project'; + } + if ($options['group_by2'] && $options['group_by2'] != 'project' && $group_by_project) { + $options['group_by3'] = 'project'; + } + return $options; + } } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 7d43e77d..df96c6a1 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
- {if $timesheet['client_id']} +{/if} +{if $timesheet['submitter_comment']} + {/if}
 Anuko Time Tracker 1.18.37.4748 | Copyright © Anuko | +  Anuko Time Tracker 1.18.37.4749 | 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 79ce95a3..dbdd42de 100644 --- a/WEB-INF/templates/timesheet_view.tpl +++ b/WEB-INF/templates/timesheet_view.tpl @@ -10,82 +10,35 @@
{$i18n.label.user}: {$timesheet['user_name']|escape}
{$i18n.label.client}: {$timesheet['client_name']|escape}
{$i18n.label.comment}: {$timesheet['submitter_comment']|escape}
-{if $invoice_items} - - - - {if $show_project} - - {/if} - {if $show_task} - - {/if} - - - - {if $user->isPluginEnabled('ps')} - - {/if} - - {foreach $invoice_items as $invoice_item} - - - - {if $show_project} - - {/if} - {if $show_task} - - {/if} - - - - {if $user->isPluginEnabled('ps')} - - {/if} - + + + + + + {foreach $subtotals as $subtotal} + + + + + {/foreach} - - {if $tax} - - - - - - - - - {/if} - - - - -
{$i18n.label.date}{$i18n.form.invoice.person}{$i18n.label.project}{$i18n.label.task}{$i18n.label.note}{$i18n.label.duration}{$i18n.label.cost}{$i18n.label.paid}
{$invoice_item.date}{$invoice_item.user_name|escape}{$invoice_item.project_name|escape}{$invoice_item.task_name|escape}{$invoice_item.note|escape}{$invoice_item.duration}{$invoice_item.cost}{if $invoice_item.paid}{$i18n.label.yes}{else}{$i18n.label.no}{/if}
{$group_by_header|escape}{$i18n.label.duration}{$i18n.label.cost}
{if $subtotal['name']}{$subtotal['name']|escape}{else} {/if}{$subtotal['time']}{if $user->can('manage_invoices') || $user->isClient()}{$subtotal['cost']}{else}{$subtotal['expenses']}{/if}
 
{$i18n.label.subtotal}:{$subtotal|escape}
{$i18n.label.tax}:{$tax|escape}
{$i18n.label.total}:{$total|escape}
- - {$forms.invoiceForm.open} - {if $user->isPluginEnabled('ps')} - - - -
- - + + + + + +
{$i18n.label.mark_paid}: {$forms.invoiceForm.mark_paid_action_options.control} {$forms.invoiceForm.btn_mark_paid.control}
 
{$i18n.label.total}{$totals['time']}{$user->currency|escape} {if $user->can('manage_invoices') || $user->isClient()}{$totals['cost']}{else}{$totals['expenses']}{/if}
- {/if} - {$forms.invoiceForm.close} -{/if} - - -
- -
diff --git a/timesheet_view.php b/timesheet_view.php index 5cbd3cfc..bbac161c 100644 --- a/timesheet_view.php +++ b/timesheet_view.php @@ -47,64 +47,14 @@ if (!$timesheet) { // TODO: add other checks here for timesheet being appropriate for user role. // End of access checks. -// $timesheet_items = ttTimesheetHelper::getTimesheetItems($timesheet_id); +$options = ttTimesheetHelper::getReportOptions($timesheet); +$subtotals = ttReportHelper::getSubtotals($options); +$totals = ttReportHelper::getTotals($options); -$currency = $user->getCurrency(); -$decimalMark = $user->getDecimalMark(); - -$smarty->assign('subtotal', $currency.' '.str_replace('.', $decimalMark, sprintf('%8.2f', round($subtotal, 2)))); -if ($tax) $smarty->assign('tax', $currency.' '.str_replace('.', $decimalMark, sprintf('%8.2f', round($tax, 2)))); -$smarty->assign('total', $currency.' '.str_replace('.', $decimalMark, sprintf('%8.2f', round($total, 2)))); - -if ('.' != $decimalMark) { - foreach ($invoice_items as &$item) - $item['cost'] = str_replace('.', $decimalMark, $item['cost']); -} - -// Calculate colspan for invoice summary. -$colspan = 4; -$trackingMode = $user->getTrackingMode(); -if (MODE_PROJECTS == $trackingMode) - $colspan++; -elseif (MODE_PROJECTS_AND_TASKS == $trackingMode) - $colspan += 2; - -$form = new Form('invoiceForm'); -// Hidden control for invoice id. -$form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_invoice_id)); -// invoiceForm only contains controls for "Mark paid" block below invoice table. -if ($user->isPluginEnabled('ps')) { - $mark_paid_action_options = array('1'=>$i18n->get('dropdown.paid'),'2'=>$i18n->get('dropdown.not_paid')); - $form->addInput(array('type'=>'combobox', - 'name'=>'mark_paid_action_options', - 'data'=>$mark_paid_action_options, - 'value'=>$cl_mark_paid_action_option)); - $form->addInput(array('type'=>'submit','name'=>'btn_mark_paid','value'=>$i18n->get('button.submit'))); -} - -if ($request->isPost()) { - if ($request->getParameter('btn_mark_paid')) { - // User clicked the "Mark paid" button to mark all invoice items either paid or not paid. - - // Determine user action. - $mark_paid = $request->getParameter('mark_paid_action_options') == 1 ? true : false; - ttInvoiceHelper::markPaid($cl_invoice_id, $mark_paid); - - // Re-display this form. - header('Location: invoice_view.php?id='.$cl_invoice_id); - exit(); - } -} - -$smarty->assign('forms', array($form->getName()=>$form->toArray())); -$smarty->assign('invoice_id', $cl_invoice_id); +$smarty->assign('group_by_header', ttReportHelper::makeGroupByHeader($options)); $smarty->assign('timesheet', $timesheet); -$smarty->assign('client_name', $client['name']); -$smarty->assign('client_address', $client['address']); -$smarty->assign('show_project', MODE_PROJECTS == $trackingMode || MODE_PROJECTS_AND_TASKS == $trackingMode); -$smarty->assign('show_task', MODE_PROJECTS_AND_TASKS == $trackingMode); -$smarty->assign('invoice_items', $invoice_items); -$smarty->assign('colspan', $colspan); +$smarty->assign('subtotals', $subtotals); +$smarty->assign('totals', $totals); $smarty->assign('title', $i18n->get('title.timesheet')); $smarty->assign('content_page_name', 'timesheet_view.tpl'); $smarty->display('index.tpl');