From 757d9db53627c00195195906033daf516be7e2b3 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Thu, 24 Apr 2025 10:28:36 +0530 Subject: [PATCH] Added line stop chart --- .../Pages/ProductionLineStopCount.php | 69 +++++++++++++++++++ .../Widgets/ProductionLineStopChart.php | 42 +++++++++++ .../production-line-stop-count.blade.php | 13 ++++ 3 files changed, 124 insertions(+) create mode 100644 app/Filament/Pages/ProductionLineStopCount.php create mode 100644 app/Filament/Widgets/ProductionLineStopChart.php create mode 100644 resources/views/filament/pages/production-line-stop-count.blade.php diff --git a/app/Filament/Pages/ProductionLineStopCount.php b/app/Filament/Pages/ProductionLineStopCount.php new file mode 100644 index 0000000..61c923b --- /dev/null +++ b/app/Filament/Pages/ProductionLineStopCount.php @@ -0,0 +1,69 @@ +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'); + } + + +} diff --git a/app/Filament/Widgets/ProductionLineStopChart.php b/app/Filament/Widgets/ProductionLineStopChart.php new file mode 100644 index 0000000..55f2a68 --- /dev/null +++ b/app/Filament/Widgets/ProductionLineStopChart.php @@ -0,0 +1,42 @@ + [ + [ + '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'); + } +} diff --git a/resources/views/filament/pages/production-line-stop-count.blade.php b/resources/views/filament/pages/production-line-stop-count.blade.php new file mode 100644 index 0000000..25effe0 --- /dev/null +++ b/resources/views/filament/pages/production-line-stop-count.blade.php @@ -0,0 +1,13 @@ + +
+ {{-- Render the Select form fields --}} +
+ {{ $this->filtersForm($this->form) }} +
+ + {{-- Render the chart widget below the form --}} +
+ @livewire(\App\Filament\Widgets\ProductionLineStopChart::class) +
+
+