1
0
forked from poc/pds

Added line stop chart

This commit is contained in:
dhanabalan
2025-04-24 10:28:36 +05:30
parent 72d56af9eb
commit 757d9db536
3 changed files with 124 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
<?php
namespace App\Filament\Pages;
use App\Models\Plant;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
use Filament\Pages\Page;
use Illuminate\Support\Facades\Auth;
class ProductionLineStopCount extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static string $view = 'filament.pages.production-line-stop-count';
protected static ?string $navigationGroup = 'Production DashBoard';
use HasFiltersForm;
public function mount(): void
{
$this->filtersForm->fill([
'plant' => Plant::first()?->id // Default to first plant
]);
}
public function filtersForm(Form $form): Form
{
return $form
->statePath('filters')
->schema([
Select::make('plant')
->options(Plant::pluck('name', 'id'))
->label('Select Plant')
->reactive()
->afterStateUpdated(function ($state) {
session(['selected_plant' => $state]);
}),
// Line Filter
Select::make('line')
->options(function ($get) {
$plantId = $get('plant');
return $plantId ? Plant::find($plantId)->getLineNames()->pluck('name', 'id') : [];
})
->label('Select Line')
->reactive()
->afterStateUpdated(function ($state) {
session(['selected_line' => $state]);
}),
])
->columns(2);
}
public static function canAccess(): bool
{
return Auth::check() && Auth::user()->can('view production line stop count dashboard');
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Filament\Widgets;
use Filament\Widgets\ChartWidget;
class ProductionLineStopChart extends ChartWidget
{
protected static ?string $heading = 'Production Line Stop Chart';
protected static ?string $maxHeight = '250px';
protected function getData(): array
{
return [
'datasets' => [
[
'label' => 'Production by Category',
'data' => [25, 40, 20, 15],
'backgroundColor' => [
'#f87171', // Red
'#60a5fa', // Blue
'#34d399', // Green
'#fbbf24', // Yellow
],
],
],
'labels' => ['Line A', 'Line B', 'Line C', 'Line D'],
];
}
protected function getType(): string
{
return 'doughnut';
}
public static function canView(): bool
{
// Only show on HourlyProduction page
return request()->routeIs('filament.pages.production-line-stop-count');
}
}