diff --git a/app/Filament/Pages/DataSendToSap.php b/app/Filament/Pages/DataSendToSap.php index 7f82c1c..93485ea 100644 --- a/app/Filament/Pages/DataSendToSap.php +++ b/app/Filament/Pages/DataSendToSap.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,8 +56,12 @@ class DataSendToSap extends Page implements HasForms ->statePath('data') ->schema([ Select::make('plant_id') - ->options(Plant::pluck('name', 'id')) ->label('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() ->required() ->afterStateUpdated(function ($state, $set, callable $get) { diff --git a/app/Filament/Pages/GuardPatrolDayCount.php b/app/Filament/Pages/GuardPatrolDayCount.php index 6711498..d97ebd7 100644 --- a/app/Filament/Pages/GuardPatrolDayCount.php +++ b/app/Filament/Pages/GuardPatrolDayCount.php @@ -4,6 +4,7 @@ namespace App\Filament\Pages; use App\Filament\Widgets\GuardPatrolDayChart; use App\Models\Plant; +use Filament\Facades\Filament; use Filament\Pages\Page; use Filament\Pages\Dashboard\Concerns\HasFiltersForm; use Filament\Forms\Form; @@ -34,13 +35,17 @@ class GuardPatrolDayCount extends Page ->statePath('filters') ->schema([ Select::make('plant') - ->options(Plant::pluck('name', 'id')) - ->label('Select Plant') - ->reactive() - ->afterStateUpdated(function ($state) { - session(['selected_plant' => $state]); - $this->dispatch('patrolEntryChart'); - }), + ->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]); + $this->dispatch('patrolEntryChart'); + }), ]); } diff --git a/app/Filament/Pages/GuardPatrolEntryDashboard.php b/app/Filament/Pages/GuardPatrolEntryDashboard.php index a9c7e98..b405cf2 100644 --- a/app/Filament/Pages/GuardPatrolEntryDashboard.php +++ b/app/Filament/Pages/GuardPatrolEntryDashboard.php @@ -5,6 +5,7 @@ namespace App\Filament\Pages; use App\Models\GuardPatrolEntry; use App\Models\Plant; use Carbon\Carbon; +use Filament\Facades\Filament; use Filament\Forms\Components\DatePicker; use Filament\Forms\Components\DateTimePicker; use Filament\Forms\Components\Select; @@ -38,8 +39,12 @@ class GuardPatrolEntryDashboard 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() ->required() ->afterStateUpdated(function ($state, callable $set, callable $get){ diff --git a/app/Filament/Pages/GuardPatrolHourlyCount.php b/app/Filament/Pages/GuardPatrolHourlyCount.php index 7f2e35d..d5c2fc0 100644 --- a/app/Filament/Pages/GuardPatrolHourlyCount.php +++ b/app/Filament/Pages/GuardPatrolHourlyCount.php @@ -8,6 +8,7 @@ use App\Models\CheckPointTime; use App\Models\GuardPatrolEntry; use App\Models\Plant; use Carbon\Carbon; +use Filament\Facades\Filament; use Filament\Pages\Page; use Filament\Pages\Dashboard\Concerns\HasFiltersForm; use Filament\Forms\Form; @@ -47,8 +48,12 @@ class GuardPatrolHourlyCount extends Page ->statePath('filters') ->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() ->required() ->afterStateUpdated(function ($state,callable $set) { diff --git a/app/Filament/Pages/LocatorValidation.php b/app/Filament/Pages/LocatorValidation.php index 90d8272..1810efd 100644 --- a/app/Filament/Pages/LocatorValidation.php +++ b/app/Filament/Pages/LocatorValidation.php @@ -69,7 +69,11 @@ class LocatorValidation extends Page implements HasForms Select::make('plant_id') ->label('Plant') ->reactive() - ->options(Plant::pluck('name', 'id')) + //->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(); + }) ->required(), TextInput::make('scan_pallet_no') ->label('Scan Pallet No') diff --git a/app/Filament/Pages/PalletFromLocator.php b/app/Filament/Pages/PalletFromLocator.php index be4e50f..8787cec 100644 --- a/app/Filament/Pages/PalletFromLocator.php +++ b/app/Filament/Pages/PalletFromLocator.php @@ -64,11 +64,15 @@ class PalletFromLocator extends Page implements HasForms Section::make('') ->schema([ Select::make('plant_id') - ->options(Plant::pluck('name', 'id')) ->label('Plant') ->reactive() ->required() ->columnSpan(1) + //->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(); + }) ->disabled(fn (Get $get) => $get('plant_id')) ->afterStateUpdated(function ($state, callable $set, callable $get) { $plantId = $get('plant_id'); diff --git a/app/Filament/Pages/StickerReprint.php b/app/Filament/Pages/StickerReprint.php index b9a6850..298ec95 100644 --- a/app/Filament/Pages/StickerReprint.php +++ b/app/Filament/Pages/StickerReprint.php @@ -122,11 +122,15 @@ class StickerReprint extends Page implements HasForms ->schema([ Select::make('plant_id') - ->options(Plant::pluck('name', 'id')) ->label('Plant') ->reactive() ->required() ->columnSpan(1) + //->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(); + }) ->default(function () { return optional(ProductionQuantity::latest()->first())->plant_id; }) diff --git a/app/Filament/Pages/UploadSerialLocator.php b/app/Filament/Pages/UploadSerialLocator.php index 6a14c53..f6d4711 100644 --- a/app/Filament/Pages/UploadSerialLocator.php +++ b/app/Filament/Pages/UploadSerialLocator.php @@ -54,10 +54,14 @@ class UploadSerialLocator extends Page implements HasForms Section::make('') // You can give your section a title or leave it blank ->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(); + }) ->disabled(fn (Get $get) => $get('scan_serial_number') || $get('scan_locator')) //!empty($get('scan_serial_number')) ->afterStateUpdated(function ($state, callable $set, callable $get) { $set('scan_serial_number', null);