Added line stop chart
This commit is contained in:
69
app/Filament/Pages/ProductionLineStopCount.php
Normal file
69
app/Filament/Pages/ProductionLineStopCount.php
Normal 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');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
42
app/Filament/Widgets/ProductionLineStopChart.php
Normal file
42
app/Filament/Widgets/ProductionLineStopChart.php
Normal 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');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<x-filament-panels::page>
|
||||||
|
<div class="space-y-4">
|
||||||
|
{{-- Render the Select form fields --}}
|
||||||
|
<div class="space-y-4">
|
||||||
|
{{ $this->filtersForm($this->form) }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{-- Render the chart widget below the form --}}
|
||||||
|
<div class="mt-6">
|
||||||
|
@livewire(\App\Filament\Widgets\ProductionLineStopChart::class)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</x-filament-panels::page>
|
||||||
Reference in New Issue
Block a user