diff --git a/app/Filament/Pages/InvoiceDashboard.php b/app/Filament/Pages/InvoiceDashboard.php index ec4abdd..ae77735 100644 --- a/app/Filament/Pages/InvoiceDashboard.php +++ b/app/Filament/Pages/InvoiceDashboard.php @@ -4,6 +4,7 @@ namespace App\Filament\Pages; use App\Models\Plant; +use Filament\Facades\Filament; use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Filament\Forms\Form; @@ -38,8 +39,12 @@ class InvoiceDashboard extends Page ->statePath('filters') // Explicitly set where to store form data ->schema([ Select::make('plant') - ->options(Plant::pluck('name', 'id')) ->label('Select Plant') + //->options(Plant::pluck('name', 'id')) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); + }) ->reactive() ->afterStateUpdated(function ($state) { session(['selec_plant' => $state]); diff --git a/app/Filament/Pages/InvoiceQuantityDashboard.php b/app/Filament/Pages/InvoiceQuantityDashboard.php index 1b55a27..0818927 100644 --- a/app/Filament/Pages/InvoiceQuantityDashboard.php +++ b/app/Filament/Pages/InvoiceQuantityDashboard.php @@ -3,6 +3,7 @@ namespace App\Filament\Pages; use App\Models\Plant; +use Filament\Facades\Filament; use Filament\Pages\Page; use Filament\Pages\Dashboard\Concerns\HasFiltersForm; use Filament\Forms\Form; @@ -35,8 +36,12 @@ class InvoiceQuantityDashboard extends Page ->statePath('filters') // Explicitly set where to store form data ->schema([ Select::make('plant') - ->options(Plant::pluck('name', 'id')) ->label('Select Plant') + //->options(Plant::pluck('name', 'id')) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); + }) ->reactive() ->afterStateUpdated(function ($state) { session(['selec_plant' => $state]); diff --git a/app/Filament/Pages/ProductionDataSap.php b/app/Filament/Pages/ProductionDataSap.php index 479add6..f45f1b4 100644 --- a/app/Filament/Pages/ProductionDataSap.php +++ b/app/Filament/Pages/ProductionDataSap.php @@ -7,6 +7,7 @@ use App\Models\Plant; use App\Models\ProductionQuantity; use App\Models\QualityValidation; use App\Models\StickerMaster; +use Filament\Facades\Filament; use Filament\Forms\Components\Actions; use Filament\Forms\Components\Actions\Action; use Filament\Forms\Form; @@ -55,10 +56,14 @@ class ProductionDataSap extends Page implements HasForms ->statePath('data') ->schema([ Select::make('plant_id') - ->options(Plant::pluck('name', 'id')) ->label('Plant') ->reactive() ->required() + //->options(Plant::pluck('name', 'id')) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); + }) ->afterStateUpdated(function ($state, $set, callable $get) { $plantId = $get('plant_id'); if (!$plantId) { diff --git a/app/Filament/Pages/ProductionLineStopCount.php b/app/Filament/Pages/ProductionLineStopCount.php index 84929fa..d77ac47 100644 --- a/app/Filament/Pages/ProductionLineStopCount.php +++ b/app/Filament/Pages/ProductionLineStopCount.php @@ -3,6 +3,7 @@ namespace App\Filament\Pages; use App\Models\Plant; +use Filament\Facades\Filament; use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Filament\Forms\Form; @@ -38,8 +39,12 @@ class ProductionLineStopCount extends Page ->schema([ Select::make('plant') - ->options(Plant::pluck('name', 'id')) ->label('Select Plant') + //->options(Plant::pluck('name', 'id')) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); + }) ->reactive() ->afterStateUpdated(function ($state) { session(['selected_plant' => $state]); diff --git a/app/Filament/Pages/TrendChartAnalys.php b/app/Filament/Pages/TrendChartAnalys.php index 7e26ed9..81924ea 100644 --- a/app/Filament/Pages/TrendChartAnalys.php +++ b/app/Filament/Pages/TrendChartAnalys.php @@ -4,6 +4,7 @@ namespace App\Filament\Pages; use App\Filament\Widgets\TrendChartAnalysis; use App\Models\MfmMeter; +use Filament\Facades\Filament; use Filament\Pages\Page; use Filament\Pages\Dashboard\Concerns\HasFiltersForm; use App\Models\Plant; @@ -37,33 +38,36 @@ class TrendChartAnalys extends Page public function filtersForm(Form $form): Form { - return $form - ->statePath('filters') - ->schema([ - - DateTimePicker::make('from_datetime') - ->label('From DateTime') - ->required() - ->before('to_datetime') - ->reactive() - ->afterStateUpdated(function ($state) { - $formatted = \Carbon\Carbon::parse($state)->format('Y-m-d H:i:s'); - session(['from_datetime' => $formatted]); - }), - DateTimePicker::make('to_datetime') - ->label('To DateTime') - ->required() - ->after('from_datetime') - ->reactive() - ->afterStateUpdated(function ($state) { - $formatted = \Carbon\Carbon::parse($state)->format('Y-m-d H:i:s'); - session(['to_datetime' => $formatted]); - }), - Select::make('plant') - ->options(Plant::pluck('name', 'id')) - ->label('Select Plant') - ->reactive() - ->required() + return $form + ->statePath('filters') + ->schema([ + DateTimePicker::make('from_datetime') + ->label('From DateTime') + ->required() + ->before('to_datetime') + ->reactive() + ->afterStateUpdated(function ($state) { + $formatted = \Carbon\Carbon::parse($state)->format('Y-m-d H:i:s'); + session(['from_datetime' => $formatted]); + }), + DateTimePicker::make('to_datetime') + ->label('To DateTime') + ->required() + ->after('from_datetime') + ->reactive() + ->afterStateUpdated(function ($state) { + $formatted = \Carbon\Carbon::parse($state)->format('Y-m-d H:i:s'); + session(['to_datetime' => $formatted]); + }), + Select::make('plant') + ->label('Select Plant') + ->reactive() + ->required() + //->options(Plant::pluck('name', 'id')) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); + }) ->afterStateUpdated(function ($state, callable $set) { session(['selected_plant' => $state]); // When plant changes, also reset meter_name @@ -71,37 +75,35 @@ class TrendChartAnalys extends Page session(['selected_meter' => null]); // dd($state); }), - - Select::make('meter_name') - ->options(function ($get) { - $plantId = $get('plant'); - // Return meter name/id pairs from mfm_meters where plant_id matches selected plant - return $plantId ? MfmMeter::where('plant_id', $plantId)->pluck('name', 'id') : []; - }) - ->label('Select Meter') - ->reactive() - ->required() - ->afterStateUpdated(function ($state) { - session(['selected_meter' => $state]); - }), - Select::make('parameter') - ->options([ - 'Phase Voltage' => 'Phase Voltage', - 'Line Voltage' => 'Line Voltage', - 'Current' => 'Current', - 'Active Power' => 'Active Power', - 'Power Factor' => 'Power Factor', - 'Units' => 'Units', - ]) - ->label('Select Parameter') - ->reactive() - ->required() - ->afterStateUpdated(function ($state) { + Select::make('meter_name') + ->options(function ($get) { + $plantId = $get('plant'); + // Return meter name/id pairs from mfm_meters where plant_id matches selected plant + return $plantId ? MfmMeter::where('plant_id', $plantId)->pluck('name', 'id') : []; + }) + ->label('Select Meter') + ->reactive() + ->required() + ->afterStateUpdated(function ($state) { + session(['selected_meter' => $state]); + }), + Select::make('parameter') + ->options([ + 'Phase Voltage' => 'Phase Voltage', + 'Line Voltage' => 'Line Voltage', + 'Current' => 'Current', + 'Active Power' => 'Active Power', + 'Power Factor' => 'Power Factor', + 'Units' => 'Units', + ]) + ->label('Select Parameter') + ->reactive() + ->required() + ->afterStateUpdated(function ($state) { session(['parameter' => $state]); - }), - - ]) - ->columns(5); + }), + ]) + ->columns(5); } public static function getNavigationLabel(): string diff --git a/app/Filament/Pages/TrendLineAnalysis.php b/app/Filament/Pages/TrendLineAnalysis.php index 55934d0..e8f43ab 100644 --- a/app/Filament/Pages/TrendLineAnalysis.php +++ b/app/Filament/Pages/TrendLineAnalysis.php @@ -3,6 +3,7 @@ namespace App\Filament\Pages; use App\Filament\Widgets\TrendLineChart; +use Filament\Facades\Filament; use Filament\Pages\Page; use Filament\Pages\Dashboard\Concerns\HasFiltersForm; use App\Models\Plant; @@ -39,66 +40,67 @@ class TrendLineAnalysis extends Page return $form ->statePath('filters') ->schema([ - - DateTimePicker::make('from_datetime') - ->label('From DateTime') - ->required() - ->before('to_datetime') - ->reactive() - ->afterStateUpdated(function ($state) { - $formatted = \Carbon\Carbon::parse($state)->format('Y-m-d H:i:s'); - session(['from_datetime' => $formatted]); - }), - DateTimePicker::make('to_datetime') - ->label('To DateTime') - ->required() - ->after('from_datetime') - ->reactive() - ->afterStateUpdated(function ($state) { - $formatted = \Carbon\Carbon::parse($state)->format('Y-m-d H:i:s'); + DateTimePicker::make('from_datetime') + ->label('From DateTime') + ->required() + ->before('to_datetime') + ->reactive() + ->afterStateUpdated(function ($state) { + $formatted = \Carbon\Carbon::parse($state)->format('Y-m-d H:i:s'); + session(['from_datetime' => $formatted]); + }), + DateTimePicker::make('to_datetime') + ->label('To DateTime') + ->required() + ->after('from_datetime') + ->reactive() + ->afterStateUpdated(function ($state) { + $formatted = \Carbon\Carbon::parse($state)->format('Y-m-d H:i:s'); session(['to_datetime' => $formatted]); - }), - Select::make('plant') - ->options(Plant::pluck('name', 'id')) - ->label('Select Plant') - ->reactive() - ->required() + }), + Select::make('plant') + ->label('Select Plant') + ->reactive() + ->required() + //->options(Plant::pluck('name', 'id')) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); + }) ->afterStateUpdated(function ($state, callable $set) { session(['selected_plant' => $state]); // When plant changes, also reset meter_name $set('meter_name', null); session(['selected_meter' => null]); - // dd($state); + // dd($state); }), - - Select::make('meter_name') - ->options(function ($get) { - $plantId = $get('plant'); - // Return meter name/id pairs from mfm_meters where plant_id matches selected plant - return $plantId ? MfmMeter::where('plant_id', $plantId)->pluck('name', 'id') : []; - }) - ->label('Select Meter') - ->reactive() - ->required() - ->afterStateUpdated(function ($state) { + Select::make('meter_name') + ->options(function ($get) { + $plantId = $get('plant'); + // Return meter name/id pairs from mfm_meters where plant_id matches selected plant + return $plantId ? MfmMeter::where('plant_id', $plantId)->pluck('name', 'id') : []; + }) + ->label('Select Meter') + ->reactive() + ->required() + ->afterStateUpdated(function ($state) { session(['selected_meter' => $state]); - }), - Select::make('parameter') - ->options([ - 'Phase Voltage' => 'Phase Voltage', - 'Line Voltage' => 'Line Voltage', - 'Current' => 'Current', - 'Active Power' => 'Active Power', - 'Power Factor' => 'Power Factor', - 'Units' => 'Units', - ]) - ->label('Select Parameter') - ->reactive() - ->required() - ->afterStateUpdated(function ($state) { + }), + Select::make('parameter') + ->options([ + 'Phase Voltage' => 'Phase Voltage', + 'Line Voltage' => 'Line Voltage', + 'Current' => 'Current', + 'Active Power' => 'Active Power', + 'Power Factor' => 'Power Factor', + 'Units' => 'Units', + ]) + ->label('Select Parameter') + ->reactive() + ->required() + ->afterStateUpdated(function ($state) { session(['parameter' => $state]); - }), - + }), ]) ->columns(5); }