$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'])
$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'])
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";
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;
+ }
}
<br>
<table cellspacing="0" cellpadding="4" width="100%" border="0">
<tr>
- <td align="center"> Anuko Time Tracker 1.18.37.4748 | Copyright © <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+ <td align="center"> Anuko Time Tracker 1.18.37.4749 | Copyright © <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
<a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
<a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
<a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>
<tr><td align="left"><b>{$i18n.label.user}:</b> {$timesheet['user_name']|escape}</td></tr>
{if $timesheet['client_id']}
<tr><td align="left"><b>{$i18n.label.client}:</b> {$timesheet['client_name']|escape}</td></tr>
+{/if}
+{if $timesheet['submitter_comment']}
+ <tr><td align="left"><b>{$i18n.label.comment}:</b> {$timesheet['submitter_comment']|escape}</td></tr>
{/if}
</table>
</td>
</tr>
<tr>
<td valign="top">
-{if $invoice_items}
<table border="0" cellpadding="3" cellspacing="1" width="100%">
- <tr>
- <td class="tableHeader">{$i18n.label.date}</td>
- <td class="tableHeader">{$i18n.form.invoice.person}</td>
- {if $show_project}
- <td class="tableHeader">{$i18n.label.project}</td>
- {/if}
- {if $show_task}
- <td class="tableHeader">{$i18n.label.task}</td>
- {/if}
- <td class="tableHeader">{$i18n.label.note}</td>
- <td class="tableHeaderCentered" width="5%">{$i18n.label.duration}</td>
- <td class="tableHeaderCentered" width="5%">{$i18n.label.cost}</td>
- {if $user->isPluginEnabled('ps')}
- <td class="tableHeader">{$i18n.label.paid}</td>
- {/if}
- </tr>
- {foreach $invoice_items as $invoice_item}
- <tr bgcolor="{cycle values="#f5f5f5,#ffffff"}">
- <td valign="top">{$invoice_item.date}</td>
- <td valign="top">{$invoice_item.user_name|escape}</td>
- {if $show_project}
- <td valign="top">{$invoice_item.project_name|escape}</td>
- {/if}
- {if $show_task}
- <td valign="top">{$invoice_item.task_name|escape}</td>
- {/if}
- <td valign="top">{$invoice_item.note|escape}</td>
- <td align="right" valign="top">{$invoice_item.duration}</td>
- <td align="right" valign="top">{$invoice_item.cost}</td>
- {if $user->isPluginEnabled('ps')}
- <td align="right" valign="top">{if $invoice_item.paid}{$i18n.label.yes}{else}{$i18n.label.no}{/if}</td>
- {/if}
- </tr>
+ <tr>
+ <td class="tableHeader">{$group_by_header|escape}</td>
+ <td class="tableHeaderCentered" width="5%">{$i18n.label.duration}</td>
+ <td class="tableHeaderCentered" width="5%">{$i18n.label.cost}</td>
+ </tr>
+ {foreach $subtotals as $subtotal}
+ <tr class="rowReportSubtotal">
+ <td class="cellLeftAlignedSubtotal">{if $subtotal['name']}{$subtotal['name']|escape}{else} {/if}</td>
+ <td class="cellRightAlignedSubtotal">{$subtotal['time']}</td>
+ <td class="cellRightAlignedSubtotal">{if $user->can('manage_invoices') || $user->isClient()}{$subtotal['cost']}{else}{$subtotal['expenses']}{/if}</td>
+ </tr>
{/foreach}
- <tr><td> </td></tr>
- {if $tax}
- <tr>
- <td align="right" colspan="{$colspan}"><b>{$i18n.label.subtotal}:</b></td>
- <td align="right"><nobr>{$subtotal|escape}</nobr></td>
- </tr>
- <tr>
- <td align="right" colspan="{$colspan}"><b>{$i18n.label.tax}:</b></td>
- <td align="right"><nobr>{$tax|escape}</nobr></td>
- </tr>
- {/if}
- <tr>
- <td align="right" colspan="{$colspan}"><b>{$i18n.label.total}:</b></td>
- <td align="right"><nobr>{$total|escape}</nobr></td>
- </tr>
- </table>
-
- {$forms.invoiceForm.open}
- {if $user->isPluginEnabled('ps')}
- <table width="720" cellspacing="0" cellpadding="0" border="0">
- <tr>
- <td align="right">
- <table>
- <tr><td>{$i18n.label.mark_paid}: {$forms.invoiceForm.mark_paid_action_options.control} {$forms.invoiceForm.btn_mark_paid.control}</td></tr>
+ <tr><td> </td></tr>
+ <tr class="rowReportSubtotal">
+ <td class="cellLeftAlignedSubtotal">{$i18n.label.total}</td>
+ <td nowrap class="cellRightAlignedSubtotal">{$totals['time']}</td>
+ <td nowrap class="cellRightAlignedSubtotal">{$user->currency|escape} {if $user->can('manage_invoices') || $user->isClient()}{$totals['cost']}{else}{$totals['expenses']}{/if}</td>
+ </tr>
</table>
</td>
</tr>
- </table>
- {/if}
- {$forms.invoiceForm.close}
-{/if}
- </td>
- </tr>
- <tr><td align="center"><br><form>
- <input type="button" onclick="chLocation('invoice_send.php?id={$invoice_id}');" value="{$i18n.button.send_by_email}">
- </form></td></tr>
</table>
// 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');