2 // +----------------------------------------------------------------------+
 
   3 // | Anuko Time Tracker
 
   4 // +----------------------------------------------------------------------+
 
   5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
 
   6 // +----------------------------------------------------------------------+
 
   7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
 
   8 // | by anyone for any purpose, and freely redistributed alone or in
 
   9 // | combination with other software, provided that the license is obeyed.
 
  11 // | There are only two ways to violate the license:
 
  13 // | 1. To redistribute this code in source form, with the copyright
 
  14 // |    notice or license removed or altered. (Distributing in compiled
 
  15 // |    forms without embedded copyright notices is permitted).
 
  17 // | 2. To redistribute modified versions of this code in *any* form
 
  18 // |    that bears insufficient indications that the modifications are
 
  19 // |    not the work of the original author(s).
 
  21 // | This license applies to this document only, not any other software
 
  22 // | that it may be combined with.
 
  24 // +----------------------------------------------------------------------+
 
  26 // | https://www.anuko.com/time_tracker/credits.htm
 
  27 // +----------------------------------------------------------------------+
 
  29 require_once('initialize.php');
 
  31 import('form.ActionForm');
 
  32 import('ttReportHelper');
 
  33 import('ttTeamHelper');
 
  36 if (!ttAccessCheck(right_view_reports)) {
 
  37   header('Location: access_denied.php');
 
  41 // Use custom fields plugin if it is enabled.
 
  42 if ($user->isPluginEnabled('cf')) {
 
  43   require_once('plugins/CustomFields.class.php');
 
  44   $custom_fields = new CustomFields($user->team_id);
 
  45   $smarty->assign('custom_fields', $custom_fields);
 
  48 $form = new Form('reportForm');
 
  50 // Report settings are stored in session bean before we get here from reports.php.
 
  51 $bean = new ActionForm('reportBean', $form, $request);
 
  52 $client_id = $bean->getAttribute('client');
 
  53 if ($client_id && $bean->getAttribute('chinvoice') && ('no_grouping' == $bean->getAttribute('group_by')) && !$user->isClient()) {
 
  54   // Client is selected and we are displaying the invoice column.
 
  55   $recent_invoices = ttTeamHelper::getRecentInvoices($user->team_id, $client_id);
 
  56   if ($recent_invoices) {
 
  57     $form->addInput(array('type'=>'combobox',
 
  58       'name'=>'recent_invoice',
 
  59       'data'=>$recent_invoices,
 
  60       'datakeys'=>array('id','name'),
 
  61       'empty'=>array(''=>$i18n->getKey('dropdown.select_invoice'))));
 
  62     $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->getKey('button.submit')));
 
  63     $smarty->assign('use_checkboxes', true);
 
  67 if ($request->isPost()) {
 
  68   if ($request->getParameter('btn_submit')) {
 
  69     // User clicked the Submit button to assign some items to a recent invoice.
 
  70     foreach($_POST as $key => $val) {
 
  71       if ('log_id_' == substr($key, 0, 7))
 
  72         $time_log_ids[] = substr($key, 7);
 
  73       if ('item_id_' == substr($key, 0, 8))
 
  74         $expense_item_ids[] = substr($key, 8);
 
  75       if ('recent_invoice' == $key)
 
  78     if ($time_log_ids || $expense_item_ids) {
 
  79       // Some records are checked for invoice editing. Adjust their invoice accordingly.
 
  80       ttReportHelper::assignToInvoice($invoice_id, $time_log_ids, $expense_item_ids);
 
  82     // Re-display this form.
 
  83     header('Location: report.php');
 
  88 $group_by = $bean->getAttribute('group_by');
 
  90 $report_items = ttReportHelper::getItems($bean);
 
  91 if ('no_grouping' != $group_by)
 
  92   $subtotals = ttReportHelper::getSubtotals($bean);
 
  93 $totals = ttReportHelper::getTotals($bean);
 
  95 // Assign variables that are used to print subtotals.
 
  96 if ($report_items && 'no_grouping' != $group_by) {
 
  97   $smarty->assign('print_subtotals', true);
 
  98   $smarty->assign('first_pass', true);
 
  99   $smarty->assign('group_by', $group_by);
 
 100   $smarty->assign('prev_grouped_by', '');
 
 101   $smarty->assign('cur_grouped_by', '');
 
 103 // Determine group by header.
 
 104 if ('no_grouping' != $group_by) {
 
 105   if ('cf_1' == $group_by)
 
 106     $smarty->assign('group_by_header', $custom_fields->fields[0]['label']);
 
 108     $key = 'label.'.$group_by;
 
 109     $smarty->assign('group_by_header', $i18n->getKey($key));
 
 112 // Assign variables that are used to alternate color of rows for different dates.
 
 113 $smarty->assign('prev_date', '');
 
 114 $smarty->assign('cur_date', '');
 
 115 $smarty->assign('report_row_class', 'rowReportItem');
 
 117 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
 
 119 $smarty->assign('report_items', $report_items);
 
 120 $smarty->assign('subtotals', $subtotals);
 
 121 $smarty->assign('totals', $totals);
 
 122 $smarty->assign('bean', $bean);
 
 123 $smarty->assign('title', $i18n->getKey('title.report').": ".$totals['start_date']." - ".$totals['end_date']);
 
 124 $smarty->assign('content_page_name', 'report.tpl');
 
 125 $smarty->display('index.tpl');