Merged getTotals and getFavTotals into one function.
authorNik Okuntseff <support@anuko.com>
Sat, 4 Aug 2018 17:36:41 +0000 (17:36 +0000)
committerNik Okuntseff <support@anuko.com>
Sat, 4 Aug 2018 17:36:41 +0000 (17:36 +0000)
WEB-INF/lib/ttReportHelper.class.php
WEB-INF/templates/footer.tpl
report.php
topdf.php

index 85078db..28a0bc5 100644 (file)
@@ -692,89 +692,7 @@ class ttReportHelper {
   }
 
   // getTotals calculates total hours and cost for all report items.
-  static function getTotals($bean, $options)
-  {
-    global $user;
-
-    $mdb2 = getConnection();
-
-    $where = ttReportHelper::getWhere($options);
-
-    // Prepare parts.
-    $time_part = "sum(time_to_sec(l.duration)) as time";
-    if ($bean->getAttribute('chunits')) {
-      $units_part = $user->unit_totals_only ? ", null as units" : ", sum(if(l.billable = 0 or time_to_sec(l.duration)/60 < $user->first_unit_threshold, 0, ceil(time_to_sec(l.duration)/60/$user->minutes_in_unit))) as units";
-    }
-    if ($bean->getAttribute('chcost')) {
-      if (MODE_TIME == $user->tracking_mode)
-        $cost_part = ", sum(cast(l.billable * coalesce(u.rate, 0) * time_to_sec(l.duration)/3600 as decimal(10,2))) as cost, null as expenses";
-      else
-        $cost_part = ", sum(cast(l.billable * coalesce(upb.rate, 0) * time_to_sec(l.duration)/3600 as decimal(10,2))) as cost, null as expenses";
-    } else {
-      $cost_part = ", null as cost, null as expenses";
-    }
-    if ($bean->getAttribute('chcost')) {
-      if (MODE_TIME == $user->tracking_mode) {
-        $left_joins = "left join tt_users u on (l.user_id = u.id)";
-      } else {
-        $left_joins = "left join tt_user_project_binds upb on (l.user_id = upb.user_id and l.project_id = upb.project_id)";
-      }
-    }
-    // Prepare a query for time items.
-    $sql = "select $time_part $units_part $cost_part from tt_log l $left_joins $where";
-
-    // If we have expenses, query becomes a bit more complex.
-    if ($bean->getAttribute('chcost') && $user->isPluginEnabled('ex')) {
-      $where = ttReportHelper::getExpenseWhere($options);
-      $sql_for_expenses = "select null as time";
-      if ($bean->getAttribute('chunits')) $sql_for_expenses .= ", null as units";
-      $sql_for_expenses .= ", sum(cost) as cost, sum(cost) as expenses from tt_expense_items ei $where";
-
-      // Create a combined query.
-      $combined = "select sum(time) as time";
-      if ($bean->getAttribute('chunits')) $combined .= ", sum(units) as units";
-      $combined .= ", sum(cost) as cost, sum(expenses) as expenses from (($sql) union all ($sql_for_expenses)) t";
-      $sql = $combined;
-    }
-
-    // Execute query.
-    $res = $mdb2->query($sql);
-    if (is_a($res, 'PEAR_Error')) die($res->getMessage());
-
-    $val = $res->fetchRow();
-    $total_time = $val['time'] ? sec_to_time_fmt_hm($val['time']) : null;
-    if ($bean->getAttribute('chcost')) {
-      $total_cost = $val['cost'];
-      if (!$total_cost) $total_cost = '0.00';
-      if ('.' != $user->decimal_mark)
-        $total_cost = str_replace('.', $user->decimal_mark, $total_cost);
-      $total_expenses = $val['expenses'];
-      if (!$total_expenses) $total_expenses = '0.00';
-      if ('.' != $user->decimal_mark)
-        $total_expenses = str_replace('.', $user->decimal_mark, $total_expenses);
-    }
-
-    if ($bean->getAttribute('period'))
-      $period = new Period($bean->getAttribute('period'), new DateAndTime($user->date_format));
-    else {
-      $period = new Period();
-      $period->setPeriod(
-        new DateAndTime($user->date_format, $bean->getAttribute('start_date')),
-        new DateAndTime($user->date_format, $bean->getAttribute('end_date')));
-    }
-
-    $totals['start_date'] = $period->getStartDate();
-    $totals['end_date'] = $period->getEndDate();
-    $totals['time'] = $total_time;
-    $totals['units'] = $val['units'];
-    $totals['cost'] = $total_cost;
-    $totals['expenses'] = $total_expenses;
-
-    return $totals;
-  }
-
-  // getFavTotals calculates total hours and cost for all favorite report items.
-  static function getFavTotals($options)
+  static function getTotals($options)
   {
     global $user;
 
@@ -905,7 +823,7 @@ class ttReportHelper {
     $group_by = $bean->getAttribute('group_by');
     if ($group_by && 'no_grouping' != $group_by)
       $subtotals = ttReportHelper::getSubtotals($bean, $options);
-    $totals = ttReportHelper::getTotals($bean, $options);
+    $totals = ttReportHelper::getTotals($options);
 
     // Use custom fields plugin if it is enabled.
     if ($user->isPluginEnabled('cf'))
@@ -1220,7 +1138,7 @@ class ttReportHelper {
     $group_by = $options['group_by'];
     if ($group_by && 'no_grouping' != $group_by)
       $subtotals = ttReportHelper::getFavSubtotals($options);
-    $totals = ttReportHelper::getFavTotals($options);
+    $totals = ttReportHelper::getTotals($options);
 
     // Use custom fields plugin if it is enabled.
     if ($user->isPluginEnabled('cf'))
index 8817aed..27bbebd 100644 (file)
@@ -12,7 +12,7 @@
       <br>
       <table cellspacing="0" cellpadding="4" width="100%" border="0">
         <tr>
-          <td align="center">&nbsp;Anuko Time Tracker 1.17.97.4313 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.17.97.4314 | Copyright &copy; <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>
index 1423706..e59c759 100644 (file)
@@ -180,7 +180,7 @@ if ($request->isGet() && $user->isPluginEnabled('ps'))
 
 if ('no_grouping' != $group_by)
   $subtotals = ttReportHelper::getSubtotals($bean, $options);
-$totals = ttReportHelper::getTotals($bean, $options);
+$totals = ttReportHelper::getTotals($options);
 
 // Assign variables that are used to print subtotals.
 if ($report_items && 'no_grouping' != $group_by) {
index b415f50..fdcbf68 100644 (file)
--- a/topdf.php
+++ b/topdf.php
@@ -79,7 +79,7 @@ if (!$totals_only)
   $items = ttReportHelper::getItems($options); // Individual entries.
 if ($totals_only || 'no_grouping' != $group_by)
   $subtotals = ttReportHelper::getSubtotals($bean, $options); // Subtotals for groups of items.
-$totals = ttReportHelper::getTotals($bean, $options); // Totals for the entire report.
+$totals = ttReportHelper::getTotals($options); // Totals for the entire report.
 
 // Assign variables that are used to print subtotals.
 if ($items && 'no_grouping' != $group_by) {