Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions app/Filament/Pages/Report.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Filament\Pages;

use Filament\Pages\Page;


class Report extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-chart-bar';
protected static string $view = 'filament.pages.report';

public static function getNavigationLabel(): string
{
return __('Report');
}

public $activeTab = 1;

}
3 changes: 3 additions & 0 deletions app/Filament/Resources/TicketResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ public static function form(Form $form): Form
->columnSpan(2)
->options(function ($livewire) {
$query = Ticket::query();
// filter hanya bulan berjalan
$query->whereMonth('created_at', now()->month)
->whereYear('created_at', now()->year);
if ($livewire instanceof EditRecord && $livewire->record) {
$query->where('id', '<>', $livewire->record->id);
}
Expand Down
25 changes: 24 additions & 1 deletion app/Filament/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ public static function form(Form $form): Form
->label(__('GitHub Username'))
->maxLength(255),

Forms\Components\Select::make('role')
->label(__('Roles'))
->options([
'devops' => 'Devops',
'support' => 'Dukungan Teknis'
]),

Forms\Components\CheckboxList::make('roles')
->label(__('Permission roles'))
->required()
Expand Down Expand Up @@ -99,8 +106,24 @@ public static function table(Table $table): Table
->searchable()
->formatStateUsing(fn ($state) => $state ?: '-'),

Tables\Columns\TagsColumn::make('roles.name')
Tables\Columns\TextColumn::make('role')
->label(__('Roles'))
->formatStateUsing(fn ($state) => match ($state) {
'support' => 'Dukungan Teknis',
'devops' => 'Devops',
default => ucfirst($state),
})
->searchable(query: function ($query, $search) {
return $query->where('role', 'like', "%{$search}%")
->orWhereRaw("CASE
WHEN role = 'support' THEN 'Dukungan Teknis'
WHEN role = 'devops' THEN 'Devops'
ELSE role
END LIKE ?", ["%{$search}%"]);
}),

Tables\Columns\TagsColumn::make('roles.name')
->label(__('Permission roles'))
->limit(2),

Tables\Columns\TextColumn::make('email_verified_at')
Expand Down
142 changes: 142 additions & 0 deletions app/Filament/Widgets/TicketByApplicationChart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php

namespace App\Filament\Widgets;

use Filament\Widgets\Widget;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Components\Select;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;
use Filament\Forms\Components\Grid;
use App\Models\MasterApplication;

class TicketByApplicationChart extends Widget implements HasForms
{
use InteractsWithForms;

protected static string $view = 'filament.widgets.ticket-by-application-chart';

public function getHeading(): string
{
return __('Trend by application');
}

public ?array $formData = [];

public function mount(): void
{
$this->form->fill([
'start_month' => now()->subMonths(2)->month,
'start_year' => now()->subMonths(2)->year,
'end_month' => now()->month,
'end_year' => now()->year,
'master_application_id' => MasterApplication::first()->id, // Default to 'Semua'
]);
}

protected function getFormSchema(): array
{
return [
Grid::make(5)->schema([
Select::make('start_month')
->label(__('Start month'))
->options($this->getMonths())
->reactive(),

Select::make('start_year')
->label(__('Start year'))
->options($this->getYears())
->reactive(),

Select::make('end_month')
->label(__('End month'))
->options($this->getMonths())
->reactive(),

Select::make('end_year')
->label(__('End year'))
->options($this->getYears())
->reactive(),

Select::make('master_application_id')
->label(__('Application'))
->options(function () {
return MasterApplication::all()->pluck('name', 'id')->toArray();
})
->reactive(),
]),

];
}

protected function getMonths(): array
{
return collect(range(1, 12))
->mapWithKeys(fn ($m) => [$m => Carbon::create()->month($m)->translatedFormat('F')])
->toArray();
}

protected function getYears(): array
{
$now = now()->year;
return collect(range($now - 2, $now))
->mapWithKeys(fn ($y) => [$y => $y])
->toArray();
}

public function getChartData(): array
{

$state = $this->form->getState();
// var_dump($state);

if (!empty($state['start_month']) && !empty($state['start_year']) && !empty($state['end_month']) && !empty($state['end_year'])) {
$start = Carbon::create($state['start_year'], $state['start_month'], 1)->startOfMonth();
$end = Carbon::create($state['end_year'], $state['end_month'], 1)->endOfMonth();
} else {
$start = now()->subMonths(2)->startOfMonth();
$end = now()->endOfMonth();
}

$tickets = DB::table('tickets')
->selectRaw("DATE_FORMAT(created_at, '%Y-%m') as bulan, COUNT(*) as total")
->whereBetween('created_at', [$start, $end])
->where('master_application_id', (int)$state['master_application_id'])
->groupBy('bulan')
->orderBy('bulan')
->get();


return [
'labels' => $tickets->pluck('bulan'),
'data' => $tickets->pluck('total'),
];
}

public function getColumnSpan(): int|string|array
{
return 'full'; // biar full 1 row
}


public function updated($name, $value): void
{
$chartData = $this->getChartData();

$this->dispatchBrowserEvent('updateApplicationChart', [
'labels' => $chartData['labels']->toArray(),
'data' => $chartData['data']->toArray(),
]);
}

public function initChart()
{
$chartData = $this->getChartData();

$this->dispatchBrowserEvent('renderApplicationChart', [
'labels' => $chartData['labels']->toArray(),
'data' => $chartData['data']->toArray(),
]);
}
}
142 changes: 142 additions & 0 deletions app/Filament/Widgets/TicketByServiceChart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php

namespace App\Filament\Widgets;

use Filament\Widgets\Widget;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Components\Select;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;
use Filament\Forms\Components\Grid;
use App\Models\Project;

class TicketByServiceChart extends Widget implements HasForms
{
use InteractsWithForms;

protected static string $view = 'filament.widgets.ticket-by-service-chart';

public function getHeading(): string
{
return __('Trend by service');
}

public ?array $formData = [];

public function mount(): void
{
$this->form->fill([
'start_month' => now()->subMonths(2)->month,
'start_year' => now()->subMonths(2)->year,
'end_month' => now()->month,
'end_year' => now()->year,
'project_id' => Project::first()->id, // Default to 'Semua'
]);
}

protected function getFormSchema(): array
{
return [
Grid::make(5)->schema([
Select::make('start_month')
->label(__('Start month'))
->options($this->getMonths())
->reactive(),

Select::make('start_year')
->label(__('Start year'))
->options($this->getYears())
->reactive(),

Select::make('end_month')
->label(__('End month'))
->options($this->getMonths())
->reactive(),

Select::make('end_year')
->label(__('End year'))
->options($this->getYears())
->reactive(),

Select::make('project_id')
->label(__('Project'))
->options(function () {
return Project::all()->pluck('name', 'id')->toArray();
})
->reactive(),
]),

];
}

protected function getMonths(): array
{
return collect(range(1, 12))
->mapWithKeys(fn ($m) => [$m => Carbon::create()->month($m)->translatedFormat('F')])
->toArray();
}

protected function getYears(): array
{
$now = now()->year;
return collect(range($now - 2, $now))
->mapWithKeys(fn ($y) => [$y => $y])
->toArray();
}

public function getChartData(): array
{

$state = $this->form->getState();
// var_dump($state);

if (!empty($state['start_month']) && !empty($state['start_year']) && !empty($state['end_month']) && !empty($state['end_year'])) {
$start = Carbon::create($state['start_year'], $state['start_month'], 1)->startOfMonth();
$end = Carbon::create($state['end_year'], $state['end_month'], 1)->endOfMonth();
} else {
$start = now()->subMonths(2)->startOfMonth();
$end = now()->endOfMonth();
}

$tickets = DB::table('tickets')
->selectRaw("DATE_FORMAT(created_at, '%Y-%m') as bulan, COUNT(*) as total")
->whereBetween('created_at', [$start, $end])
->where('project_id', (int)$state['project_id'])
->groupBy('bulan')
->orderBy('bulan')
->get();


return [
'labels' => $tickets->pluck('bulan'),
'data' => $tickets->pluck('total'),
];
}

public function getColumnSpan(): int|string|array
{
return 'full'; // biar full 1 row
}


public function updated($name, $value): void
{
$chartData = $this->getChartData();

$this->dispatchBrowserEvent('updateServiceChart', [
'labels' => $chartData['labels']->toArray(),
'data' => $chartData['data']->toArray(),
]);
}

public function initChart()
{
$chartData = $this->getChartData();

$this->dispatchBrowserEvent('renderServiceChart', [
'labels' => $chartData['labels']->toArray(),
'data' => $chartData['data']->toArray(),
]);
}
}
Loading