From 1b984b0c5f3ac0977c993d5bcff456bbd372f5bf Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Thu, 21 Feb 2019 13:32:57 +0000 Subject: [PATCH] Starting work on timesheet view. --- WEB-INF/templates/report.tpl | 5 + WEB-INF/templates/timesheet_view.tpl | 90 ++++++++++++++++++ invoice_view.php | 2 +- timesheet_view.php | 131 +++++++++++++++++++++++++++ 4 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 WEB-INF/templates/timesheet_view.tpl create mode 100644 timesheet_view.php diff --git a/WEB-INF/templates/report.tpl b/WEB-INF/templates/report.tpl index 3cd8e40e..b603dd27 100644 --- a/WEB-INF/templates/report.tpl +++ b/WEB-INF/templates/report.tpl @@ -53,6 +53,7 @@ {if $bean->getAttribute('chpaid')}{$i18n.label.paid}{/if} {if $bean->getAttribute('chip')}{$i18n.label.ip}{/if} {if $bean->getAttribute('chinvoice')}{$i18n.label.invoice}{/if} + {if $bean->getAttribute('chtimesheet')}{$i18n.label.timesheet}{/if} {foreach $report_items as $item} @@ -76,6 +77,7 @@ {if $bean->getAttribute('chpaid')}{/if} {if $bean->getAttribute('chip')}{/if} {if $bean->getAttribute('chinvoice')}{/if} + {if $bean->getAttribute('chtimesheet')}{/if} {if $use_checkboxes}{/if}   @@ -102,6 +104,7 @@ {if $bean->getAttribute('chpaid')}{if $item.paid == 1}{$i18n.label.yes}{else}{$i18n.label.no}{/if}{/if} {if $bean->getAttribute('chip')}{if $item.modified}{$item.modified_ip} {$item.modified}{else}{$item.created_ip} {$item.created}{/if}{/if} {if $bean->getAttribute('chinvoice')}{$item.invoice|escape}{/if} + {if $bean->getAttribute('chtimesheet')}{$item.timesheet_id|escape}{/if} {if $use_checkboxes} {if 1 == $item.type}{/if} {if 2 == $item.type}{/if} @@ -128,6 +131,7 @@ {if $bean->getAttribute('chpaid')}{/if} {if $bean->getAttribute('chip')}{/if} {if $bean->getAttribute('chinvoice')}{/if} + {if $bean->getAttribute('chtimesheet')}{/if} {if $use_checkboxes}{/if} {/if} @@ -149,6 +153,7 @@ {if $bean->getAttribute('chpaid')}{/if} {if $bean->getAttribute('chip')}{/if} {if $bean->getAttribute('chinvoice')}{/if} + {if $bean->getAttribute('chtimesheet')}{/if} {if $use_checkboxes}{/if} {/if} diff --git a/WEB-INF/templates/timesheet_view.tpl b/WEB-INF/templates/timesheet_view.tpl new file mode 100644 index 00000000..736d65b0 --- /dev/null +++ b/WEB-INF/templates/timesheet_view.tpl @@ -0,0 +1,90 @@ + + + + + + + + + + +
+ + + + + +
{$timesheet_name|escape}
{$i18n.label.date}: {$invoice_date}
{$i18n.label.client}: {$client_name|escape}
{$i18n.label.client_address}: {$client_address|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} + + {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}
 
{$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}
+
+ {/if} + {$forms.invoiceForm.close} +{/if} +

+ +
diff --git a/invoice_view.php b/invoice_view.php index 64831798..605a5302 100644 --- a/invoice_view.php +++ b/invoice_view.php @@ -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 index 00000000..136c7f11 --- /dev/null +++ b/timesheet_view.php @@ -0,0 +1,131 @@ +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'); -- 2.20.1