Starting work on timesheet view.
authorNik Okuntseff <support@anuko.com>
Thu, 21 Feb 2019 13:32:57 +0000 (13:32 +0000)
committerNik Okuntseff <support@anuko.com>
Thu, 21 Feb 2019 13:32:57 +0000 (13:32 +0000)
WEB-INF/templates/report.tpl
WEB-INF/templates/timesheet_view.tpl [new file with mode: 0644]
invoice_view.php
timesheet_view.php [new file with mode: 0644]

index 3cd8e40..b603dd2 100644 (file)
@@ -53,6 +53,7 @@
   {if $bean->getAttribute('chpaid')}<td class="tableHeader">{$i18n.label.paid}</td>{/if}
   {if $bean->getAttribute('chip')}<td class="tableHeaderCentered">{$i18n.label.ip}</td>{/if}
   {if $bean->getAttribute('chinvoice')}<td class="tableHeader">{$i18n.label.invoice}</td>{/if}
+  {if $bean->getAttribute('chtimesheet')}<td class="tableHeader">{$i18n.label.timesheet}</td>{/if}
       </tr>
   {foreach $report_items as $item}
     <!-- print subtotal for a block of grouped values -->
@@ -76,6 +77,7 @@
         {if $bean->getAttribute('chpaid')}<td></td>{/if}
         {if $bean->getAttribute('chip')}<td></td>{/if}
         {if $bean->getAttribute('chinvoice')}<td></td>{/if}
+        {if $bean->getAttribute('chtimesheet')}<td></td>{/if}
         {if $use_checkboxes}<td></td>{/if}
       </tr>
       <tr><td>&nbsp;</td></tr>
     {if $bean->getAttribute('chpaid')}<td class="cellRightAligned">{if $item.paid == 1}{$i18n.label.yes}{else}{$i18n.label.no}{/if}{/if}
     {if $bean->getAttribute('chip')}<td class="cellRightAligned">{if $item.modified}{$item.modified_ip} {$item.modified}{else}{$item.created_ip} {$item.created}{/if}{/if}
     {if $bean->getAttribute('chinvoice')}<td class="cellRightAligned">{$item.invoice|escape}</td>{/if}
+    {if $bean->getAttribute('chtimesheet')}<td class="cellRightAligned">{$item.timesheet_id|escape}</td>{/if}
     {if $use_checkboxes}
       {if 1 == $item.type}<td bgcolor="white"><input type="checkbox" name="log_id_{$item.id}"></td>{/if}
       {if 2 == $item.type}<td bgcolor="white"><input type="checkbox" name="item_id_{$item.id}"></td>{/if}
     {if $bean->getAttribute('chpaid')}<td></td>{/if}
     {if $bean->getAttribute('chip')}<td></td>{/if}
     {if $bean->getAttribute('chinvoice')}<td></td>{/if}
+    {if $bean->getAttribute('chtimesheet')}<td></td>{/if}
     {if $use_checkboxes}<td></td>{/if}
       </tr>
   {/if}
     {if $bean->getAttribute('chpaid')}<td></td>{/if}
     {if $bean->getAttribute('chip')}<td></td>{/if}
     {if $bean->getAttribute('chinvoice')}<td></td>{/if}
+    {if $bean->getAttribute('chtimesheet')}<td></td>{/if}
     {if $use_checkboxes}<td></td>{/if}
       </tr>
 {/if}
diff --git a/WEB-INF/templates/timesheet_view.tpl b/WEB-INF/templates/timesheet_view.tpl
new file mode 100644 (file)
index 0000000..736d65b
--- /dev/null
@@ -0,0 +1,90 @@
+<script>
+  function chLocation(newLocation) { document.location = newLocation; }
+</script>
+
+<table cellspacing="0" cellpadding="7" border="0" width="720">
+  <tr>
+    <td>
+      <table border=0 width=100%>
+        <tr><td align="center"><b style="font-size: 15pt; font-family: Arial, Helvetica, sans-serif;">{$timesheet_name|escape} </b></td></tr>
+        <tr><td align="left"><b>{$i18n.label.date}:</b> {$invoice_date}</td></tr>
+        <tr><td align="left"><b>{$i18n.label.client}:</b> {$client_name|escape}</td></tr>
+        <tr><td align="left"><b>{$i18n.label.client_address}:</b> {$client_address|escape}</td></tr>
+      </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>
+  {/foreach}
+        <tr><td>&nbsp;</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>
+      </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>
index 6483179..605a530 100644 (file)
@@ -69,7 +69,7 @@ if ($tax_percent > 0) {
     $tax += round($item['cost'] * $tax_percent / 100, 2);
   }
 }
-$total = $subtotal + $tax; 
+$total = $subtotal + $tax;
 
 $currency = $user->getCurrency();
 $decimalMark = $user->getDecimalMark();
diff --git a/timesheet_view.php b/timesheet_view.php
new file mode 100644 (file)
index 0000000..136c7f1
--- /dev/null
@@ -0,0 +1,131 @@
+<?php
+// +----------------------------------------------------------------------+
+// | Anuko Time Tracker
+// +----------------------------------------------------------------------+
+// | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
+// +----------------------------------------------------------------------+
+// | LIBERAL FREEWARE LICENSE: This source code document may be used
+// | by anyone for any purpose, and freely redistributed alone or in
+// | combination with other software, provided that the license is obeyed.
+// |
+// | There are only two ways to violate the license:
+// |
+// | 1. To redistribute this code in source form, with the copyright
+// |    notice or license removed or altered. (Distributing in compiled
+// |    forms without embedded copyright notices is permitted).
+// |
+// | 2. To redistribute modified versions of this code in *any* form
+// |    that bears insufficient indications that the modifications are
+// |    not the work of the original author(s).
+// |
+// | This license applies to this document only, not any other software
+// | that it may be combined with.
+// |
+// +----------------------------------------------------------------------+
+// | Contributors:
+// | https://www.anuko.com/time_tracker/credits.htm
+// +----------------------------------------------------------------------+
+
+require_once('initialize.php');
+import('ttTimesheetHelper');
+
+// Access checks.
+if (!(ttAccessAllowed('view_own_timesheets') || ttAccessAllowed('view_timesheets') || ttAccessAllowed('view_all_timesheets') || ttAccessAllowed('view_client_timesheets'))) {
+  header('Location: access_denied.php');
+  exit();
+}
+if (!$user->isPluginEnabled('ts')) {
+  header('Location: feature_disabled.php');
+  exit();
+}
+$timesheet_id = (int)$request->getParameter('id');
+$timesheet = ttTimesheetHelper::getTimesheet($timesheet_id);
+if (!$timesheet) {
+  header('Location: access_denied.php');
+  exit();
+}
+// TODO: add other checks here for timesheet being appropriate for user role.
+// End of access checks.
+
+$invoice_date = new DateAndTime(DB_DATEFORMAT, $invoice['date']);
+$client = ttClientHelper::getClient($invoice['client_id'], true);
+if (!$client) // In case client was deleted.
+  $client = ttClientHelper::getDeletedClient($invoice['client_id']);
+
+$invoice_items = ttInvoiceHelper::getInvoiceItems($cl_invoice_id);
+$tax_percent = $client['tax'];
+
+$subtotal = 0;
+$tax = 0;
+foreach($invoice_items as $item)
+  $subtotal += $item['cost'];
+if ($tax_percent > 0) {
+  $tax_expenses = $user->isPluginEnabled('et');
+  foreach($invoice_items as $item) {
+    if ($item['type'] == 2 && !$tax_expenses)
+      continue;
+    $tax += round($item['cost'] * $tax_percent / 100, 2);
+  }
+}
+$total = $subtotal + $tax;
+
+$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('timesheet_name', $timesheet['name']);
+$smarty->assign('invoice_date', $invoice_date->toString($user->getDateFormat()));
+$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('title', $i18n->get('title.timesheet'));
+$smarty->assign('content_page_name', 'timesheet_view.tpl');
+$smarty->display('index.tpl');