From de20a2009639bd1064c8d2b61a79d449c352409c Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Sun, 22 Jul 2018 17:31:54 +0000 Subject: [PATCH] Added work units in output for emailed reports. --- WEB-INF/lib/ttReportHelper.class.php | 30 +++++++++++++++++++++++++--- WEB-INF/templates/footer.tpl | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/WEB-INF/lib/ttReportHelper.class.php b/WEB-INF/lib/ttReportHelper.class.php index 170dc2a9..224d7f17 100644 --- a/WEB-INF/lib/ttReportHelper.class.php +++ b/WEB-INF/lib/ttReportHelper.class.php @@ -1078,26 +1078,30 @@ class ttReportHelper { if ($report['show_cost']) { if (MODE_TIME == $user->tracking_mode) { $sql = "select sum(time_to_sec(l.duration)) as time, + 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, sum(cast(l.billable * coalesce(u.rate, 0) * time_to_sec(l.duration)/3600 as decimal(10,2))) as cost, null as expenses from tt_log l left join tt_users u on (l.user_id = u.id) $where"; } else { $sql = "select sum(time_to_sec(l.duration)) as time, + 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, sum(cast(l.billable * coalesce(upb.rate, 0) * time_to_sec(l.duration)/3600 as decimal(10,2))) as cost, null as expenses from tt_log l left join tt_user_project_binds upb on (l.user_id = upb.user_id and l.project_id = upb.project_id) $where"; } } else - $sql = "select sum(time_to_sec(l.duration)) as time, null as cost, null as expenses from tt_log l $where"; + $sql = "select sum(time_to_sec(l.duration)) as time, + 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, + null as cost, null as expenses from tt_log l $where"; // If we have expenses, query becomes a bit more complex. if ($report['show_cost'] && $user->isPluginEnabled('ex')) { $where = ttReportHelper::getFavExpenseWhere($report); - $sql_for_expenses = "select null as time, sum(cost) as cost, sum(cost) as expenses from tt_expense_items ei $where"; + $sql_for_expenses = "select null as time, null as units, sum(cost) as cost, sum(cost) as expenses from tt_expense_items ei $where"; // Create a combined query. - $sql = "select sum(time) as time, sum(cost) as cost, sum(expenses) as expenses from (($sql) union all ($sql_for_expenses)) t"; + $sql = "select sum(time) as time, sum(units) as units, sum(cost) as cost, sum(expenses) as expenses from (($sql) union all ($sql_for_expenses)) t"; } // Execute query. @@ -1129,6 +1133,7 @@ class ttReportHelper { $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; @@ -1229,6 +1234,8 @@ class ttReportHelper { $body .= ''.$group_by_header.''; if ($bean->getAttribute('chduration')) $body .= ''.$i18n->get('label.duration').''; + if ($bean->getAttribute('chunits')) + $body .= ''.$i18n->get('label.work_units_short').''; if ($bean->getAttribute('chcost')) $body .= ''.$i18n->get('label.cost').''; $body .= ''; @@ -1240,6 +1247,11 @@ class ttReportHelper { if ($subtotal['time'] <> '0:00') $body .= $subtotal['time']; $body .= ''; } + if ($bean->getAttribute('chunits')) { + $body .= ''; + $body .= $subtotal['units']; + $body .= ''; + } if ($bean->getAttribute('chcost')) { $body .= ''; $body .= ($canViewReports || $isClient) ? $subtotal['cost'] : $subtotal['expenses']; @@ -1257,6 +1269,11 @@ class ttReportHelper { if ($totals['time'] <> '0:00') $body .= $totals['time']; $body .= ''; } + if ($bean->getAttribute('chunits')) { + $body .= ''; + $body .= $totals['units']; + $body .= ''; + } if ($bean->getAttribute('chcost')) { $body .= ''.htmlspecialchars($user->currency).' '; $body .= ($canViewReports || $isClient) ? $totals['cost'] : $totals['expenses']; @@ -1288,6 +1305,8 @@ class ttReportHelper { $body .= ''.$i18n->get('label.finish').''; if ($bean->getAttribute('chduration')) $body .= ''.$i18n->get('label.duration').''; + if ($bean->getAttribute('chunits')) + $body .= ''.$i18n->get('label.work_units_short').''; if ($bean->getAttribute('chnote')) $body .= ''.$i18n->get('label.note').''; if ($bean->getAttribute('chcost')) @@ -1331,6 +1350,7 @@ class ttReportHelper { if ($bean->getAttribute('chstart')) $body .= ''; if ($bean->getAttribute('chfinish')) $body .= ''; if ($bean->getAttribute('chduration')) $body .= ''.$subtotals[$prev_grouped_by]['time'].''; + if ($bean->getAttribute('chunits')) $body .= ''.$subtotals[$prev_grouped_by]['units'].''; if ($bean->getAttribute('chnote')) $body .= ''; if ($bean->getAttribute('chcost')) { $body .= ''; @@ -1367,6 +1387,8 @@ class ttReportHelper { $body .= ''.$record['finish'].''; if ($bean->getAttribute('chduration')) $body .= ''.$record['duration'].''; + if ($bean->getAttribute('chunits')) + $body .= ''.$record['units'].''; if ($bean->getAttribute('chnote')) $body .= ''.htmlspecialchars($record['note']).''; if ($bean->getAttribute('chcost')) @@ -1404,6 +1426,7 @@ class ttReportHelper { if ($bean->getAttribute('chstart')) $body .= ''; if ($bean->getAttribute('chfinish')) $body .= ''; if ($bean->getAttribute('chduration')) $body .= ''.$subtotals[$cur_grouped_by]['time'].''; + if ($bean->getAttribute('chunits')) $body .= ''.$subtotals[$cur_grouped_by]['units'].''; if ($bean->getAttribute('chnote')) $body .= ''; if ($bean->getAttribute('chcost')) { $body .= ''; @@ -1428,6 +1451,7 @@ class ttReportHelper { if ($bean->getAttribute('chstart')) $body .= ''; if ($bean->getAttribute('chfinish')) $body .= ''; if ($bean->getAttribute('chduration')) $body .= ''.$totals['time'].''; + if ($bean->getAttribute('chunits')) $body .= ''.$totals['units'].''; if ($bean->getAttribute('chnote')) $body .= ''; if ($bean->getAttribute('chcost')) { $body .= ''.htmlspecialchars($user->currency).' '; diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 1b04936f..8f0779f2 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.17.92.4282 | Copyright © Anuko | +  Anuko Time Tracker 1.17.92.4283 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} -- 2.20.1