diff --git a/app/Filament/Resources/AsrsItemValidationResource.php b/app/Filament/Resources/AsrsItemValidationResource.php index c826e81..81d6f37 100644 --- a/app/Filament/Resources/AsrsItemValidationResource.php +++ b/app/Filament/Resources/AsrsItemValidationResource.php @@ -19,6 +19,11 @@ use Filament\Tables\Actions\ExportAction; use Filament\Tables\Actions\ImportAction; use Filament\Forms\Get; use App\Models\Item; +use Filament\Tables\Filters\Filter; +use Filament\Forms\Components\Select; +use Filament\Forms\Components\TextInput; +use Filament\Forms\Components\DateTimePicker; +use App\Models\Plant; class AsrsItemValidationResource extends Resource { @@ -71,6 +76,16 @@ class AsrsItemValidationResource extends Resource ->readOnly() ->reactive() ->disabledOn('edit'), + Forms\Components\TextInput::make('material_type') + ->label('Material Type') + ->readOnly() + ->reactive() + ->disabledOn('edit'), + Forms\Components\TextInput::make('material_group') + ->label('Material Group') + ->readOnly() + ->reactive() + ->disabledOn('edit'), Forms\Components\Select::make('mhe') ->label('MHE') ->options([ @@ -143,6 +158,14 @@ class AsrsItemValidationResource extends Resource ->label('UOM') ->alignCenter() ->searchable(), + Tables\Columns\TextColumn::make('material_type') + ->label('Material Type') + ->alignCenter() + ->searchable(), + Tables\Columns\TextColumn::make('material_group') + ->label('Material Group') + ->alignCenter() + ->searchable(), Tables\Columns\TextColumn::make('mhe') ->label('MHE') ->alignCenter() @@ -178,7 +201,146 @@ class AsrsItemValidationResource extends Resource ]) ->filters([ Tables\Filters\TrashedFilter::make(), + Filter::make('advanced_filters') + ->label('Advanced Filters') + ->form([ + Select::make('Plant') + ->label('Search by Plant Name') + ->nullable() + ->searchable() + ->reactive() + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + + if ($userHas && strlen($userHas) > 0) { + return Plant::where('id', $userHas)->pluck('name', 'id')->toArray(); + } else { + return Plant::whereHas('vehicleEntries', function ($query) { + $query->whereNotNull('id'); + })->orderBy('code')->pluck('name', 'id'); + } + + // return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); + }) + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $set('item_code', null); + }), + Select::make('item_code') + ->label('Item Code') + ->reactive() + ->searchable() + ->options(function (callable $get) { + + $plantId = $get('Plant'); + + if (!$plantId) { + return []; + } + + return AsrsItemValidation::where('plant_id', $plantId) + ->pluck('item_code', 'item_code') + ->toArray(); + }) + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $set('Rework', null); + }), + Select::make('status') + ->label('Status') + ->reactive() + ->searchable() + ->options(function (callable $get) { + + $plantId = $get('Plant'); + + if (!$plantId) { + return []; + } + + return [ + 'Updated' => 'Updated', + 'NotUpdated' => 'Not Updated', + ]; + }) + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $set('Rework', null); + }), + DateTimePicker::make('created_from') + ->label('Created From') + ->placeholder('Select From DateTime') + ->reactive() + ->native(false), + DateTimePicker::make('created_to') + ->label('Created To') + ->placeholder('Select To DateTime') + ->reactive() + ->native(false), + ]) + ->query(function ($query, array $data) { + // Hide all records initially if no filters are applied + if (empty($data['Plant']) && empty($data['item_code']) && empty($data['status']) && empty($data['created_from']) && empty($data['created_to'])) { + return $query->whereRaw('1 = 0'); + } + + if (! empty($data['Plant'])) { + $query->where('plant_id', $data['Plant']); + } else { + $userHas = Filament::auth()->user()->plant_id; + + if ($userHas && strlen($userHas) > 0) { + return $query->whereRaw('1 = 0'); + } + } + + if (! empty($data['item_code'])) { + $query->where('item_code', 'like', '%'.$data['item_code'].'%'); + } + + if (! empty($data['status'])) { + $query->where('status', $data['status']); + } + + if (! empty($data['created_from'])) { + $query->where('created_at', '>=', $data['created_from']); + } + + if (! empty($data['created_to'])) { + $query->where('created_at', '<=', $data['created_to']); + } + // $query->orderBy('created_at', 'asc'); + }) + ->indicateUsing(function (array $data) { + $indicators = []; + + if (! empty($data['Plant'])) { + $indicators[] = 'Plant Name: '.Plant::where('id', $data['Plant'])->value('name'); + } else { + $userHas = Filament::auth()->user()->plant_id; + + if ($userHas && strlen($userHas) > 0) { + return 'Plant Name: Choose plant to filter records.'; + } + } + + if (! empty($data['item_code'])) { + $indicators[] = 'Item Code: '.$data['item_code']; + } + + if (! empty($data['status'])) { + $indicators[] = 'Status: '.$data['status']; + } + + if (! empty($data['created_from'])) { + $indicators[] = 'From: '.$data['created_from']; + } + + if (! empty($data['created_to'])) { + $indicators[] = 'To: '.$data['created_to']; + } + + return $indicators; + }), ]) + ->filtersFormMaxHeight('280px') ->actions([ Tables\Actions\ViewAction::make(), Tables\Actions\EditAction::make(), diff --git a/app/Models/AsrsItemValidation.php b/app/Models/AsrsItemValidation.php index d8b0ddb..46af1eb 100644 --- a/app/Models/AsrsItemValidation.php +++ b/app/Models/AsrsItemValidation.php @@ -20,6 +20,8 @@ class AsrsItemValidation extends Model 'asrs', 'asrs_category', 'status', + 'material_type', + 'material_group', 'created_at', 'updated_at', 'created_by', diff --git a/database/migrations/2026_05_26_092955_add_column_material_type_and_material_group_to_asrs_item_validations.php b/database/migrations/2026_05_26_092955_add_column_material_type_and_material_group_to_asrs_item_validations.php new file mode 100644 index 0000000..70b07b0 --- /dev/null +++ b/database/migrations/2026_05_26_092955_add_column_material_type_and_material_group_to_asrs_item_validations.php @@ -0,0 +1,38 @@ +