From 5425970fc2345eaf610a1bde3eb4e67ce57e9f58 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Wed, 23 Apr 2025 20:53:31 +0530 Subject: [PATCH] updated dashboards --- app/Filament/Pages/Dashboard.php | 4 +- app/Filament/Pages/HourlyProduction.php | 6 +- app/Filament/Pages/InvoiceDashboard.php | 4 +- app/Filament/Pages/ProductionOrderCount.php | 87 +++++++++++++++++++++ 4 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 app/Filament/Pages/ProductionOrderCount.php diff --git a/app/Filament/Pages/Dashboard.php b/app/Filament/Pages/Dashboard.php index 0015708..e74e4df 100644 --- a/app/Filament/Pages/Dashboard.php +++ b/app/Filament/Pages/Dashboard.php @@ -18,11 +18,11 @@ class Dashboard extends \Filament\Pages\Dashboard protected static ?string $navigationGroup = 'Production DashBoard'; - public function mount(): void { + session()->forget(['selected_plant']); $this->filtersForm->fill([ - 'plant' => Plant::first()?->id // Default to first plant + 'plant' => null ]); } diff --git a/app/Filament/Pages/HourlyProduction.php b/app/Filament/Pages/HourlyProduction.php index 71866ce..321474c 100644 --- a/app/Filament/Pages/HourlyProduction.php +++ b/app/Filament/Pages/HourlyProduction.php @@ -20,11 +20,13 @@ class HourlyProduction extends Page use HasFiltersForm; - public function mount(): void { + session()->forget(['selected_plant', 'selected_line']); $this->filtersForm->fill([ - 'plant' => Plant::first()?->id // Default to first plant + //'plant' => Plant::first()?->id // Default to first plant + 'plant' => null, + 'line' => null, ]); } diff --git a/app/Filament/Pages/InvoiceDashboard.php b/app/Filament/Pages/InvoiceDashboard.php index d0ca004..49a2e03 100644 --- a/app/Filament/Pages/InvoiceDashboard.php +++ b/app/Filament/Pages/InvoiceDashboard.php @@ -25,8 +25,10 @@ class InvoiceDashboard extends Page public function mount(): void { + session()->forget(['selec_plant', 'select_invoice']); $this->filtersForm->fill([ - 'plant' => Plant::first()?->id // Default to first plant + 'plant' => null, + 'invoice' => null, ]); } diff --git a/app/Filament/Pages/ProductionOrderCount.php b/app/Filament/Pages/ProductionOrderCount.php new file mode 100644 index 0000000..42217dc --- /dev/null +++ b/app/Filament/Pages/ProductionOrderCount.php @@ -0,0 +1,87 @@ +forget(['selected_plant', 'selected_line', 'production_order']); + $this->filtersForm->fill([ + 'plant' => null, + 'line' => null, + 'production_order' => null, + ]); + } + + + public function filtersForm(Form $form): Form + { + return $form + ->statePath('filters') // Explicitly set where to store form data + ->schema([ + Select::make('plant') + ->options(Plant::pluck('name', 'id')) + ->label('Select Plant') + ->reactive() + ->afterStateUpdated(function ($state) { + session(['selected_plant' => $state]); + $this->triggerChartUpdate(); + }), + // 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]); // Store in session + $this->triggerChartUpdate(); + }), + + // Production Order Text Input + TextInput::make('production_order') + ->label('Production Order') + ->reactive() + ->afterStateUpdated(function ($state) { + session(['production_order' => $state]); + $this->triggerChartUpdate(); + }), + ]) + ->columns(3); + } + + // public function triggerChartUpdate(): void + // { + // if (session()->has('selected_plant') && session()->has('selected_line') && session()->has('production_order')) { + // $this->dispatch('productionOrderChart'); + // } + // } + + public function triggerChartUpdate(): void + { + $filters = $this->filtersForm->getState(); + + if (!empty($filters['plant']) && !empty($filters['line']) && !empty($filters['production_order'])) { + $this->dispatch('productionOrderChart', filters: $filters); + } + } +}