Skip to content

Commit

Permalink
Count spent time by spent_at column instead of created_at. Filter by …
Browse files Browse the repository at this point in the history
…spent_at, update translations, zubroide#63
  • Loading branch information
danielciobanica committed Aug 28, 2020
1 parent 142b888 commit dd2eb0e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions app/Console/Commands/StatSpentTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ public function handle()
$stat = [];
foreach ($data as $item) {
$stat[] = [
$item['gitlab_created_at'],
$item['project'],
$item['spent_at'],
'#' . $item['iid'] . ' ' . $item['issue_title'],
$item['hours'],
$item['note_description'],
// $item['note_description'],
];
$total += $item['hours'];
}

$this->table(['gitlab_created_at', 'project', 'issue', 'hours', 'description'], $stat);
$this->table(['spent_at', 'issue', 'hours'], $stat);
// $this->table(['spent_at', 'project', 'issue', 'hours', 'description'], $stat);

$this->warn(sprintf('Total spent time: %s', TimeHelper::getHoursIntervalAsString($total)));
}
Expand Down
14 changes: 7 additions & 7 deletions app/Model/Repository/SpentRepositoryEloquent.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ public function getListQuery(array $parameters): Builder
if ($dateStart = Arr::get($parameters, 'date_start'))
{
$date = new \DateTime($dateStart);
$query->where('note.gitlab_created_at', '>=', $date->format('Y-m-d'));
$query->where('spent.spent_at', '>=', $date->format('Y-m-d'));
}

if ($dateEnd = Arr::get($parameters, 'date_end'))
{
$date = new \DateTime($dateEnd);
$date->add(new \DateInterval('P1D'));
$query->where('note.gitlab_created_at', '<', $date->format('Y-m-d'));
$query->where('spent.spent_at', '<', $date->format('Y-m-d'));
}

if ($labels = Arr::get($parameters, 'labels'))
Expand All @@ -94,7 +94,7 @@ public function getTNMListQuery(array $parameters): Builder
{
$query = $this->getListQuery($parameters);
$query = $query->select([
DB::raw("date_trunc('second', max(note.gitlab_created_at)) as gitlab_created_at"),
DB::raw("date_trunc('second', max(spent.spent_at)) as gitlab_created_at"),
'issue.iid as issue',
'issue.title as title',
DB::raw('sum(spent.hours) as hours'),
Expand All @@ -114,7 +114,7 @@ public function stat($parameters): Collection

$query = $query
->select([
'note.gitlab_created_at',
'spent.spent_at',
'project.path_with_namespace as project',
'issue.iid',
'issue.title as issue_title',
Expand All @@ -126,11 +126,11 @@ public function stat($parameters): Collection
->join('project', 'project.id', '=', 'issue.project_id');

if ($dateStart = Arr::get($parameters, 'date_start')) {
$query->where('note.gitlab_created_at', '>=', $dateStart);
$query->where('spent.spent_at', '>=', $dateStart);
}

if ($dateFinish = Arr::get($parameters, 'date_finish')) {
$query->where('note.gitlab_created_at', '<', $dateFinish);
$query->where('spent.spent_at', '<', $dateFinish);
}

if ($userId = Arr::get($parameters, 'user_id')) {
Expand All @@ -151,7 +151,7 @@ public function stat($parameters): Collection

$query
->orderBy('issue.iid', 'asc')
->orderBy('note.gitlab_created_at', 'asc');
->orderBy('spent.spent_at', 'asc');

return $query->get();
}
Expand Down
2 changes: 1 addition & 1 deletion app/Model/Service/Eloquent/EloquentSpentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class EloquentSpentService extends CrudServiceAbstract
{
const DEFAULT_ORDER_COLUMN = 'note.gitlab_created_at';
const DEFAULT_ORDER_COLUMN = 'spent.spent_at';

public function __construct()
{
Expand Down
2 changes: 1 addition & 1 deletion resources/views/gitpab/time/index_filter_form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
'date_start' => $request->get('date_start'),
'date_end' => $request->get('date_end'),
],
'label' => __('messages.Created At'),
'label' => __('messages.Spent at'),
])
</div>
</div>
Expand Down

0 comments on commit dd2eb0e

Please sign in to comment.