-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/display billable hours #347
base: develop
Are you sure you want to change the base?
Changes from all commits
693adc1
4cccf8c
8ee0b9a
40b80ea
ae05565
41f02f0
07f9d43
5d295e9
dff97d7
c8513c1
c6a4e07
c34d52d
f74184a
6761754
134163a
027940b
42fbda1
3429c97
18e88c3
5aaeb92
8546622
17dfae8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1116,4 +1116,46 @@ public function navList(): array | |
new MenuLinkStruct("Task Groups", "task-group/viewtaskgrouptypes"), | ||
]; | ||
} | ||
|
||
public function getTotalTimeByTimeType($task_id) { | ||
$all_tasks = TaskService::getInstance($this->w)->getTasks(); | ||
foreach ($all_tasks as $task) { | ||
if ($task->id == $task_id) { | ||
$current_task = $task; | ||
} | ||
} | ||
$all_timelogs_for_task = TimelogService::getInstance($this->w)->getTimelogsForObject($current_task); | ||
|
||
$config_var = Config::get('task.TaskType_' . $current_task->task_type); | ||
if (!array_key_exists('time-types', $config_var)) { | ||
return; | ||
} | ||
$timelog_types = $config_var['time-types']; | ||
|
||
$time_totals_for_time_types = []; | ||
foreach ($timelog_types as $timelog_type) { | ||
$total_time_for_type = 0; | ||
foreach ($all_timelogs_for_task as $timelog) { | ||
if ($timelog->time_type == $timelog_type) { | ||
$total_time_for_type += $timelog->getDuration(); | ||
} | ||
$total_time_fmtd = floor($total_time_for_type / 3600) . gmdate(":i:s", $total_time_for_type) . ' '; | ||
} | ||
$time_totals_for_time_types[$timelog_type] = $total_time_fmtd; | ||
} | ||
return $time_totals_for_time_types; | ||
} | ||
|
||
public function getTotalTimeByBillable($task_id) { | ||
$time_totals = $this->getTotalTimeByTimeType($task_id); | ||
$time_totals_in_seconds = []; | ||
foreach ($time_totals as $time_total) { | ||
$time_totals_in_seconds[] = strtotime("1970-01-01 $time_total UTC"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there any other way to do this? DateTime perhaps? https://www.php.net/manual/en/class.datetime.php |
||
} | ||
$billable_time_in_seconds = array_sum(array_merge(array_slice($time_totals_in_seconds, 0, 3), [$time_totals_in_seconds[4]])); | ||
$billable_time = floor($billable_time_in_seconds / 3600) . gmdate(":i:s", $billable_time_in_seconds); | ||
$nonbillable_time = floor($time_totals_in_seconds[3] / 3600) . gmdate(":i:s", $time_totals_in_seconds[3]); | ||
return ['Billable' => substr($billable_time, 0, -3), 'Non-Billable' => substr($nonbillable_time, 0, -3)]; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,5 +28,4 @@ public function getComment() { | |
public function getTask() { | ||
return $this->getObject("Task", $this->task_id); | ||
} | ||
|
||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we move all the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be possible to have getTotalTimeByTimeType return a map of timetypes to total minutes, as opposed to formatted hour/minute strings? this would make the maths of adding things up a lot easier in getTotalTimeByBillable, make things a bit more readable?