Refactor plant selection options by authenticated user's plant ID.
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Models\Plant;
|
|||||||
use App\Models\ProductionQuantity;
|
use App\Models\ProductionQuantity;
|
||||||
use App\Models\QualityValidation;
|
use App\Models\QualityValidation;
|
||||||
use App\Models\StickerMaster;
|
use App\Models\StickerMaster;
|
||||||
|
use Filament\Facades\Filament;
|
||||||
use Filament\Forms\Components\Actions;
|
use Filament\Forms\Components\Actions;
|
||||||
use Filament\Forms\Components\Actions\Action;
|
use Filament\Forms\Components\Actions\Action;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
@@ -55,8 +56,12 @@ class DataSendToSap extends Page implements HasForms
|
|||||||
->statePath('data')
|
->statePath('data')
|
||||||
->schema([
|
->schema([
|
||||||
Select::make('plant_id')
|
Select::make('plant_id')
|
||||||
->options(Plant::pluck('name', 'id'))
|
|
||||||
->label('Plant')
|
->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()
|
->reactive()
|
||||||
->required()
|
->required()
|
||||||
->afterStateUpdated(function ($state, $set, callable $get) {
|
->afterStateUpdated(function ($state, $set, callable $get) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\Filament\Pages;
|
|||||||
|
|
||||||
use App\Filament\Widgets\GuardPatrolDayChart;
|
use App\Filament\Widgets\GuardPatrolDayChart;
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
|
use Filament\Facades\Filament;
|
||||||
use Filament\Pages\Page;
|
use Filament\Pages\Page;
|
||||||
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
|
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
@@ -34,13 +35,17 @@ class GuardPatrolDayCount extends Page
|
|||||||
->statePath('filters')
|
->statePath('filters')
|
||||||
->schema([
|
->schema([
|
||||||
Select::make('plant')
|
Select::make('plant')
|
||||||
->options(Plant::pluck('name', 'id'))
|
->label('Select Plant')
|
||||||
->label('Select Plant')
|
// ->options(Plant::pluck('name', 'id'))
|
||||||
->reactive()
|
->options(function (callable $get) {
|
||||||
->afterStateUpdated(function ($state) {
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
session(['selected_plant' => $state]);
|
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||||
$this->dispatch('patrolEntryChart');
|
})
|
||||||
}),
|
->reactive()
|
||||||
|
->afterStateUpdated(function ($state) {
|
||||||
|
session(['selected_plant' => $state]);
|
||||||
|
$this->dispatch('patrolEntryChart');
|
||||||
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace App\Filament\Pages;
|
|||||||
use App\Models\GuardPatrolEntry;
|
use App\Models\GuardPatrolEntry;
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Filament\Facades\Filament;
|
||||||
use Filament\Forms\Components\DatePicker;
|
use Filament\Forms\Components\DatePicker;
|
||||||
use Filament\Forms\Components\DateTimePicker;
|
use Filament\Forms\Components\DateTimePicker;
|
||||||
use Filament\Forms\Components\Select;
|
use Filament\Forms\Components\Select;
|
||||||
@@ -38,8 +39,12 @@ class GuardPatrolEntryDashboard extends Page
|
|||||||
->statePath('filters') // Explicitly set where to store form data
|
->statePath('filters') // Explicitly set where to store form data
|
||||||
->schema([
|
->schema([
|
||||||
Select::make('plant')
|
Select::make('plant')
|
||||||
->options(Plant::pluck('name', 'id'))
|
|
||||||
->label('Select Plant')
|
->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()
|
->reactive()
|
||||||
->required()
|
->required()
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get){
|
->afterStateUpdated(function ($state, callable $set, callable $get){
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use App\Models\CheckPointTime;
|
|||||||
use App\Models\GuardPatrolEntry;
|
use App\Models\GuardPatrolEntry;
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Filament\Facades\Filament;
|
||||||
use Filament\Pages\Page;
|
use Filament\Pages\Page;
|
||||||
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
|
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
@@ -47,8 +48,12 @@ class GuardPatrolHourlyCount extends Page
|
|||||||
->statePath('filters')
|
->statePath('filters')
|
||||||
->schema([
|
->schema([
|
||||||
Select::make('plant')
|
Select::make('plant')
|
||||||
->options(Plant::pluck('name', 'id'))
|
|
||||||
->label('Select Plant')
|
->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()
|
->reactive()
|
||||||
->required()
|
->required()
|
||||||
->afterStateUpdated(function ($state,callable $set) {
|
->afterStateUpdated(function ($state,callable $set) {
|
||||||
|
|||||||
@@ -69,7 +69,11 @@ class LocatorValidation extends Page implements HasForms
|
|||||||
Select::make('plant_id')
|
Select::make('plant_id')
|
||||||
->label('Plant')
|
->label('Plant')
|
||||||
->reactive()
|
->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(),
|
->required(),
|
||||||
TextInput::make('scan_pallet_no')
|
TextInput::make('scan_pallet_no')
|
||||||
->label('Scan Pallet No')
|
->label('Scan Pallet No')
|
||||||
|
|||||||
@@ -64,11 +64,15 @@ class PalletFromLocator extends Page implements HasForms
|
|||||||
Section::make('')
|
Section::make('')
|
||||||
->schema([
|
->schema([
|
||||||
Select::make('plant_id')
|
Select::make('plant_id')
|
||||||
->options(Plant::pluck('name', 'id'))
|
|
||||||
->label('Plant')
|
->label('Plant')
|
||||||
->reactive()
|
->reactive()
|
||||||
->required()
|
->required()
|
||||||
->columnSpan(1)
|
->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'))
|
->disabled(fn (Get $get) => $get('plant_id'))
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
|
|||||||
@@ -122,11 +122,15 @@ class StickerReprint extends Page implements HasForms
|
|||||||
->schema([
|
->schema([
|
||||||
|
|
||||||
Select::make('plant_id')
|
Select::make('plant_id')
|
||||||
->options(Plant::pluck('name', 'id'))
|
|
||||||
->label('Plant')
|
->label('Plant')
|
||||||
->reactive()
|
->reactive()
|
||||||
->required()
|
->required()
|
||||||
->columnSpan(1)
|
->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 () {
|
->default(function () {
|
||||||
return optional(ProductionQuantity::latest()->first())->plant_id;
|
return optional(ProductionQuantity::latest()->first())->plant_id;
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -54,10 +54,14 @@ class UploadSerialLocator extends Page implements HasForms
|
|||||||
Section::make('') // You can give your section a title or leave it blank
|
Section::make('') // You can give your section a title or leave it blank
|
||||||
->schema([
|
->schema([
|
||||||
Select::make('plant_id')
|
Select::make('plant_id')
|
||||||
->options(Plant::pluck('name', 'id'))
|
|
||||||
->label('Plant')
|
->label('Plant')
|
||||||
->reactive()
|
->reactive()
|
||||||
->required()
|
->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'))
|
->disabled(fn (Get $get) => $get('scan_serial_number') || $get('scan_locator')) //!empty($get('scan_serial_number'))
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$set('scan_serial_number', null);
|
$set('scan_serial_number', null);
|
||||||
|
|||||||
Reference in New Issue
Block a user