Skip to content

Commit 21b1d6e

Browse files
authored
Merge pull request #40 from devaslanphp/master
Merge master into dev
2 parents f15ad4b + 3abb619 commit 21b1d6e

File tree

4 files changed

+149
-0
lines changed

4 files changed

+149
-0
lines changed

app/Filament/Pages/Dashboard.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
namespace App\Filament\Pages;
44

5+
use App\Filament\Widgets\FavoriteProjects;
6+
use App\Filament\Widgets\LatestActivities;
7+
use App\Filament\Widgets\LatestComments;
8+
use App\Filament\Widgets\LatestProjects;
9+
use App\Filament\Widgets\LatestTickets;
10+
use App\Filament\Widgets\TicketsByPriority;
11+
use App\Filament\Widgets\TicketsByType;
12+
use App\Filament\Widgets\TicketTimeLogged;
13+
use App\Filament\Widgets\UserTimeLogged;
514
use Filament\Pages\Dashboard as BasePage;
615

716
class Dashboard extends BasePage
@@ -12,4 +21,19 @@ protected function getColumns(): int | array
1221
{
1322
return 6;
1423
}
24+
25+
protected function getWidgets(): array
26+
{
27+
return [
28+
FavoriteProjects::class,
29+
LatestActivities::class,
30+
LatestComments::class,
31+
LatestProjects::class,
32+
LatestTickets::class,
33+
TicketsByPriority::class,
34+
TicketsByType::class,
35+
TicketTimeLogged::class,
36+
UserTimeLogged::class
37+
];
38+
}
1539
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace App\Filament\Pages;
4+
5+
use App\Filament\Widgets\Timesheet\MonthlyReport;
6+
use Filament\Pages\Page;
7+
8+
class TimesheetDashboard extends Page
9+
{
10+
protected static ?string $slug = 'timesheet-dashboard';
11+
12+
protected static ?int $navigationSort = 1;
13+
14+
protected static string $view = 'filament::pages.dashboard';
15+
16+
protected function getColumns(): int | array
17+
{
18+
return 6;
19+
}
20+
21+
protected static function getNavigationLabel(): string
22+
{
23+
return __('Dashboard');
24+
}
25+
26+
protected static function getNavigationGroup(): ?string
27+
{
28+
return __('Timesheet');
29+
}
30+
31+
protected function getWidgets(): array
32+
{
33+
return [
34+
MonthlyReport::class
35+
];
36+
}
37+
}

app/Filament/Resources/TimesheetResource.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public static function table(Table $table): Table
7979
->searchable(),
8080
Tables\Columns\TextColumn::make('comment')
8181
->label(__('Comment'))
82+
->limit(50)
8283
->sortable()
8384
->searchable(),
8485

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Filament\Widgets\Timesheet;
6+
7+
use App\Models\TicketHour;
8+
use App\Models\User;
9+
use Carbon\Carbon;
10+
use Filament\Widgets\BarChartWidget;
11+
use Illuminate\Support\Facades\DB;
12+
13+
class MonthlyReport extends BarChartWidget
14+
{
15+
protected function getHeading(): string
16+
{
17+
return __('Logged time monthly');
18+
}
19+
20+
protected function getData(): array
21+
{
22+
$months = [
23+
1 => ['January', 0],
24+
2 => ['February', 0],
25+
3 => ['March', 0],
26+
4 => ['April', 0],
27+
5 => ['May', 0],
28+
6 => ['June', 0],
29+
7 => ['July', 0],
30+
8 => ['August', 0],
31+
9 => ['September', 0],
32+
10 => ['October', 0],
33+
11 => ['November', 0],
34+
12 => ['December', 0]
35+
];
36+
37+
38+
$data = $this->filter(auth()->user());
39+
40+
foreach ($data as $value) {
41+
if (isset($months[(int)$value->month])) {
42+
$months[(int)$value->month][1] = (float)$value->value;
43+
}
44+
}
45+
46+
$datasets = [];
47+
$labels = [];
48+
foreach ($months as $month) {
49+
$datasets[] = $month[1];
50+
$labels[] = $month[0];
51+
}
52+
53+
return [
54+
'datasets' => [
55+
[
56+
'label' => __('Total time logged'),
57+
'data' => $datasets,
58+
'backgroundColor' => [
59+
'rgba(54, 162, 235, .6)'
60+
],
61+
'borderColor' => [
62+
'rgba(54, 162, 235, .8)'
63+
],
64+
],
65+
],
66+
'labels' => $labels,
67+
];
68+
}
69+
70+
protected int|string|array $columnSpan = [
71+
'sm' => 1,
72+
'md' => 6,
73+
'lg' => 3
74+
];
75+
76+
protected function filter(User $user)
77+
{
78+
return TicketHour::select([
79+
DB::raw("DATE_FORMAT (created_at, '%m') as month"),
80+
DB::raw('SUM(value) as value'),
81+
])
82+
->where('user_id', $user->id)
83+
->whereRaw(DB::raw("YEAR(created_at)=") . Carbon::now()->format('Y'))
84+
->groupBy(DB::raw("DATE_FORMAT (created_at, '%m')"))
85+
->get();
86+
}
87+
}

0 commit comments

Comments
 (0)