From 8ec1dac1bcf71ce282ab116413d335f582b5e8f3 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Sun, 22 Jul 2018 17:53:59 +0000 Subject: [PATCH] Added work units to emailed fav reports. --- WEB-INF/lib/ttReportHelper.class.php | 52 +++++++++++++++++++++------- WEB-INF/templates/footer.tpl | 2 +- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/WEB-INF/lib/ttReportHelper.class.php b/WEB-INF/lib/ttReportHelper.class.php index 224d7f17..0900f7f9 100644 --- a/WEB-INF/lib/ttReportHelper.class.php +++ b/WEB-INF/lib/ttReportHelper.class.php @@ -276,6 +276,9 @@ class ttReportHelper { // Add duration. if ($bean->getAttribute('chduration')) array_push($fields, "TIME_FORMAT(l.duration, '%k:%i') as duration"); + // Add work units. + if ($bean->getAttribute('chunits')) + array_push($fields, "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"); // Add note. if ($bean->getAttribute('chnote')) array_push($fields, 'l.comment as note'); @@ -303,10 +306,6 @@ class ttReportHelper { if (($canViewReports || $isClient) && $bean->getAttribute('chinvoice')) array_push($fields, 'i.name as invoice'); - // Add work units. - if ($bean->getAttribute('chunits')) - array_push($fields, "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"); - // Prepare sql query part for left joins. $left_joins = null; if ($bean->getAttribute('chclient') || 'client' == $group_by_option) @@ -549,6 +548,10 @@ class ttReportHelper { // Add duration. if ($report['show_duration']) array_push($fields, "TIME_FORMAT(l.duration, '%k:%i') as duration"); + // Add work units. + if ($report['show_work_units']) + array_push($fields, "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"); + // Add note. if ($report['show_note']) array_push($fields, 'l.comment as note'); @@ -632,6 +635,8 @@ class ttReportHelper { array_push($fields, 'null'); // null for finish. if ($report['show_duration']) array_push($fields, 'null'); // null for duration. + if ($report['show_work_units']) + array_push($fields, 'null'); // null for work units. // Use the note field to print item name. if ($report['show_note']) array_push($fields, 'ei.name as note'); @@ -909,21 +914,25 @@ class ttReportHelper { if (MODE_TIME == $user->tracking_mode) { if ($group_by_option != 'user') $left_join = 'left join tt_users u on (l.user_id = u.id)'; - $sql = "select $group_field as group_field, sum(time_to_sec(l.duration)) as time, + $sql = "select $group_field as group_field, 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 $group_join $left_join $where group by $group_field"; } else { // If we are including cost and tracking projects, our query (the same as above) needs to join the tt_user_project_binds table. - $sql = "select $group_field as group_field, sum(time_to_sec(l.duration)) as time, + $sql = "select $group_field as group_field, 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 $group_join left join tt_user_project_binds upb on (l.user_id = upb.user_id and l.project_id = upb.project_id) $where group by $group_field"; } } else { - $sql = "select $group_field as group_field, sum(time_to_sec(l.duration)) as time, null as expenses from tt_log l - $group_join $where group by $group_field"; + $sql = "select $group_field as group_field, 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 expenses from tt_log l + $group_join $where group by $group_field"; } // By now we have sql for time items. @@ -953,13 +962,13 @@ class ttReportHelper { } $where = ttReportHelper::getFavExpenseWhere($report); - $sql_for_expenses = "select $group_field as group_field, null as time, sum(ei.cost) as cost, sum(ei.cost) as expenses from tt_expense_items ei + $sql_for_expenses = "select $group_field as group_field, null as time, null as units, sum(ei.cost) as cost, sum(ei.cost) as expenses from tt_expense_items ei $group_join $where"; // Add a "group by" clause if we are grouping. if ('null' != $group_field) $sql_for_expenses .= " group by $group_field"; // Create a combined query. - $sql = "select group_field, sum(time) as time, sum(cost) as cost, sum(expenses) as expenses from (($sql) union all ($sql_for_expenses)) t group by group_field"; + $sql = "select group_field, sum(time) as time, sum(units) as units, sum(cost) as cost, sum(expenses) as expenses from (($sql) union all ($sql_for_expenses)) t group by group_field"; } // Execute query. @@ -979,9 +988,9 @@ class ttReportHelper { $val['cost'] = str_replace('.', $user->decimal_mark, $val['cost']); $val['expenses'] = str_replace('.', $user->decimal_mark, $val['expenses']); } - $subtotals[$val['group_field']] = array('name'=>$val['group_field'],'time'=>$time,'cost'=>$val['cost'],'expenses'=>$val['expenses']); + $subtotals[$val['group_field']] = array('name'=>$val['group_field'],'time'=>$time, 'units'=> $val['units'], 'cost'=>$val['cost'],'expenses'=>$val['expenses']); } else - $subtotals[$val['group_field']] = array('name'=>$val['group_field'],'time'=>$time); + $subtotals[$val['group_field']] = array('name'=>$val['group_field'],'time'=>$time, 'units'=> $val['units']); } return $subtotals; @@ -1549,6 +1558,8 @@ class ttReportHelper { $body .= ''.$group_by_header.''; if ($report['show_duration']) $body .= ''.$i18n->get('label.duration').''; + if ($report['show_work_units']) + $body .= ''.$i18n->get('label.work_units_short').''; if ($report['show_cost']) $body .= ''.$i18n->get('label.cost').''; $body .= ''; @@ -1560,6 +1571,11 @@ class ttReportHelper { if ($subtotal['time'] <> '0:00') $body .= $subtotal['time']; $body .= ''; } + if ($report['show_work_units']) { + $body .= ''; + $body .= $subtotal['units']; + $body .= ''; + } if ($report['show_cost']) { $body .= ''; $body .= ($canViewReports || $isClient) ? $subtotal['cost'] : $subtotal['expenses']; @@ -1577,6 +1593,11 @@ class ttReportHelper { if ($totals['time'] <> '0:00') $body .= $totals['time']; $body .= ''; } + if ($report['show_work_units']) { + $body .= ''; + $body .= $totals['units']; + $body .= ''; + } if ($report['show_cost']) { $body .= ''.htmlspecialchars($user->currency).' '; $body .= ($canViewReports || $isClient) ? $totals['cost'] : $totals['expenses']; @@ -1608,6 +1629,8 @@ class ttReportHelper { $body .= ''.$i18n->get('label.finish').''; if ($report['show_duration']) $body .= ''.$i18n->get('label.duration').''; + if ($report['show_work_units']) + $body .= ''.$i18n->get('label.work_units_short').''; if ($report['show_note']) $body .= ''.$i18n->get('label.note').''; if ($report['show_cost']) @@ -1651,6 +1674,7 @@ class ttReportHelper { if ($report['show_start']) $body .= ''; if ($report['show_end']) $body .= ''; if ($report['show_duration']) $body .= ''.$subtotals[$prev_grouped_by]['time'].''; + if ($report['show_work_units']) $body .= ''.$subtotals[$prev_grouped_by]['units'].''; if ($report['show_note']) $body .= ''; if ($report['show_cost']) { $body .= ''; @@ -1687,6 +1711,8 @@ class ttReportHelper { $body .= ''.$record['finish'].''; if ($report['show_duration']) $body .= ''.$record['duration'].''; + if ($report['show_work_units']) + $body .= ''.$record['units'].''; if ($report['show_note']) $body .= ''.htmlspecialchars($record['note']).''; if ($report['show_cost']) @@ -1724,6 +1750,7 @@ class ttReportHelper { if ($report['show_start']) $body .= ''; if ($report['show_end']) $body .= ''; if ($report['show_duration']) $body .= ''.$subtotals[$cur_grouped_by]['time'].''; + if ($report['show_work_units']) $body .= ''.$subtotals[$cur_grouped_by]['units'].''; if ($report['show_note']) $body .= ''; if ($report['show_cost']) { $body .= ''; @@ -1748,6 +1775,7 @@ class ttReportHelper { if ($report['show_start']) $body .= ''; if ($report['show_end']) $body .= ''; if ($report['show_duration']) $body .= ''.$totals['time'].''; + if ($report['show_work_units']) $body .= ''.$totals['units'].''; if ($report['show_note']) $body .= ''; if ($report['show_cost']) { $body .= ''.htmlspecialchars($user->currency).' '; diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 8f0779f2..c2010946 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.17.92.4283 | Copyright © Anuko | +  Anuko Time Tracker 1.17.92.4284 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} -- 2.20.1