diff --git a/app/Filament/Resources/WeightValidationResource.php b/app/Filament/Resources/WeightValidationResource.php index 16ed82a..94798e6 100644 --- a/app/Filament/Resources/WeightValidationResource.php +++ b/app/Filament/Resources/WeightValidationResource.php @@ -13,6 +13,7 @@ use Filament\Facades\Filament; use Filament\Forms; use Filament\Forms\Components\DateTimePicker; use Filament\Forms\Components\FileUpload; +use Filament\Forms\Components\Section; use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Filament\Forms\Form; @@ -42,41 +43,83 @@ class WeightValidationResource extends Resource { return $form ->schema([ - Forms\Components\Select::make('plant_id') - ->relationship('plant', 'name') - ->options(function (callable $get) { - $userHas = Filament::auth()->user()->plant_id; + Section::make('') + ->schema([ + Forms\Components\Select::make('plant_id') + ->label('Plant Name') + ->relationship('plant', 'name') + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; - return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); - }) - ->required(), - Forms\Components\Select::make('item_id') - ->relationship('item', 'code') - ->label('Item Code') - ->searchable() - ->required(), - Forms\Components\TextInput::make('obd_number') - ->label('OBD Number') - ->required(), - Forms\Components\TextInput::make('line_number') - ->label('Line Number') - ->required(), - Forms\Components\TextInput::make('batch_number') - ->label('Batch Number') - ->required(), - Forms\Components\TextInput::make('obd_weight') - ->label('Actual Weight') - ->required(), - Forms\Components\TextInput::make('vehicle_number') - ->label('Vehicle Number'), - Forms\Components\TextInput::make('heat_number') - ->label('Heat Number'), - Forms\Components\TextInput::make('bundle_number') - ->label('Bundle Number'), - Forms\Components\TextInput::make('picked_weight') - ->label('Picked Weight'), - Forms\Components\TextInput::make('scanned_by') - ->label('Scanned By'), + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); + }) + ->columnSpan(1) + ->required(), + Forms\Components\Select::make('item_id') + ->relationship('item', 'code') + ->label('Item Code') + ->searchable() + ->columnSpan(1) + ->required(), + Forms\Components\TextInput::make('obd_number') + ->label('OBD Number') + ->minLength(8) + ->placeholder('Scan the valid OBD Number') + ->columnSpan(1) + ->required(), + Forms\Components\TextInput::make('line_number') + ->label('Line Number') + ->minLength(1) + ->integer() + ->columnSpan(1) + ->placeholder('Scan the valid Line Number') + ->required(), + Forms\Components\TextInput::make('batch_number') + ->label('Batch Number') + ->minLength(8) + ->numeric() + ->columnSpan(1) + ->placeholder('Scan the valid Batch Number') + ->required(), + Forms\Components\TextInput::make('obd_weight') + ->label('Actual Weight') + ->minLength(1) + ->numeric() + ->columnSpan(1) + ->placeholder('Scan the valid Actual Weight') + ->required(), + Forms\Components\TextInput::make('vehicle_number') + ->label('Vehicle Number') + ->minLength(10) + ->columnSpan(1) + ->placeholder('Scan the valid Vehicle Number'), + Forms\Components\TextInput::make('heat_number') + ->label('Heat Number') + ->minLength(4) + ->columnSpan(1) + ->placeholder('Scan the valid Heat Number'), + Forms\Components\TextInput::make('bundle_number') + ->label('Bundle Number') + ->minLength(1) + ->numeric() + ->columnSpan(1) + ->placeholder('Scan the valid Bundle Number'), + Forms\Components\TextInput::make('picked_weight') + ->label('Picked Weight') + ->minLength(1) + ->numeric() + ->columnSpan(1) + ->placeholder('Scan the valid Picked Weight'), + Forms\Components\TextInput::make('scanned_by') + ->label('Scanned By') + ->minLength(3) + ->columnSpan(1) + ->placeholder('Scan the valid Scanned By'), + Forms\Components\TextInput::make('id') + ->hidden() + ->readOnly(), + ]) + ->columns(['default' => 1, 'sm' => 2]), ]); } @@ -98,7 +141,7 @@ class WeightValidationResource extends Resource return ($currentPage - 1) * $perPage + $rowLoop->iteration; }), Tables\Columns\TextColumn::make('plant.name') - ->label('Plant') + ->label('Plant Name') ->alignCenter() ->sortable() ->searchable(), @@ -160,7 +203,7 @@ class WeightValidationResource extends Resource ->label('Advanced Filters') ->form([ Select::make('Plant') - ->label('Select Plant') + ->label('Search by Plant Name') ->nullable() // ->options(function () { // return Plant::pluck('name', 'id'); @@ -168,25 +211,24 @@ class WeightValidationResource extends Resource ->options(function (callable $get) { $userHas = Filament::auth()->user()->plant_id; - return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); + // return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); + if ($userHas && strlen($userHas) > 0) { + return Plant::where('id', $userHas)->pluck('name', 'id')->toArray(); + } else { + return Plant::whereHas('weightValidations', function ($query) { + $query->whereNotNull('id'); + })->orderBy('code')->pluck('name', 'id')->toArray(); + } }) - ->reactive(), - // ->afterStateUpdated(function ($state, callable $set, callable $get) { - // $set('sticker_master_id', null); - // $set('sap_msg_status', null); - // }), + ->searchable() + ->reactive() + ->afterStateUpdated(function ($state, callable $set, callable $get): void { + $set('Item Code', null); + }), Select::make('Item Code') ->label('Search by Item Code') ->nullable() - // ->options(function (callable $get) { - // $plantId = $get('Plant'); - // if (! $plantId) { - // return []; - // } - - // return Item::where('plant_id', $plantId)->pluck('code', 'id'); - // }) ->options(function (callable $get) { $plantId = $get('Plant'); if (! $plantId) { @@ -207,16 +249,23 @@ class WeightValidationResource extends Resource ->placeholder('Enter OBD Number'), Select::make('Line') - ->label('Line') + ->label('Line Number') ->options(function (callable $get) { $plantId = $get('Plant'); - + $itemCode = $get('Item Code'); if (! $plantId) { return []; + } elseif (! $itemCode) { + return WeightValidation::where('plant_id', $plantId) + ->distinct() + ->orderBy('line_number') + ->pluck('line_number', 'line_number') + ->toArray(); } // Get unique line_numbers for the selected plant_id return WeightValidation::where('plant_id', $plantId) + ->where('item_id', $itemCode) ->distinct() ->orderBy('line_number') ->pluck('line_number', 'line_number') @@ -285,31 +334,31 @@ class WeightValidationResource extends Resource } if (! empty($data['Obd Number'])) { - $query->where('obd_number', $data['Obd Number']); + $query->where('obd_number', 'like', '%'.$data['Obd Number'].'%'); } if (! empty($data['Batch'])) { - $query->where('batch_number', $data['Batch']); + $query->where('batch_number', 'like', '%'.$data['Batch'].'%'); } if (! empty($data['Actual Weight'])) { - $query->where('actual_weight', $data['Actual Weight']); + $query->where('actual_weight', 'like', '%'.$data['Actual Weight'].'%'); } if (! empty($data['Vehicle Number'])) { - $query->where('vehicle_number', $data['Vehicle Number']); + $query->where('vehicle_number', 'like', '%'.$data['Vehicle Number'].'%'); } if (! empty($data['Heat Number'])) { - $query->where('heat_number', $data['Heat Number']); + $query->where('heat_number', 'like', '%'.$data['Heat Number'].'%'); } if (! empty($data['Bundle Number'])) { - $query->where('bundle_number', $data['Bundle Number']); + $query->where('bundle_number', 'like', '%'.$data['Bundle Number'].'%'); } if (! empty($data['Scanned By'])) { - $query->where('scanned_by', $data['Scanned By']); + $query->where('scanned_by', 'like', '%'.$data['Scanned By'].'%'); } if (! empty($data['created_from'])) { @@ -324,7 +373,7 @@ class WeightValidationResource extends Resource $indicators = []; if (! empty($data['Plant'])) { - $indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name'); + $indicators[] = 'Plant Name : '.Plant::where('id', $data['Plant'])->value('name'); } else { $userHas = Filament::auth()->user()->plant_id; @@ -334,19 +383,19 @@ class WeightValidationResource extends Resource } if (! empty($data['Item Code'])) { - $indicators[] = 'Item Code: '.Item::where('id', $data['Item Code'])->value('code'); + $indicators[] = 'Item Code : '.Item::where('id', $data['Item Code'])->value('code'); } if (! empty($data['Line'])) { - $indicators[] = 'Line: '.$data['Line']; + $indicators[] = 'Line : '.$data['Line']; } if (! empty($data['Obd Number'])) { - $indicators[] = 'OBD Number: '.$data['Obd Number']; + $indicators[] = 'OBD Number : '.$data['Obd Number']; } if (! empty($data['Batch'])) { - $indicators[] = 'Batch Number: '.$data['Batch']; + $indicators[] = 'Batch Number : '.$data['Batch']; } if (! empty($data['Actual Weight'])) { @@ -354,32 +403,32 @@ class WeightValidationResource extends Resource } if (! empty($data['Vehicle Number'])) { - $indicators[] = 'Vehicle Number: '.$data['Vehicle Number']; + $indicators[] = 'Vehicle Number : '.$data['Vehicle Number']; } if (! empty($data['Heat Number'])) { - $indicators[] = 'Heat Number: '.$data['Heat Number']; + $indicators[] = 'Heat Number : '.$data['Heat Number']; } if (! empty($data['Bundle Number'])) { - $indicators[] = 'Bundle Number: '.$data['Bundle Number']; + $indicators[] = 'Bundle Number : '.$data['Bundle Number']; } if (! empty($data['Scanned By'])) { - $indicators[] = 'Scanned By: '.$data['Scanned By']; + $indicators[] = 'Scanned By : '.$data['Scanned By']; } if (! empty($data['created_from'])) { - $indicators[] = 'From: '.$data['created_from']; + $indicators[] = 'From : '.$data['created_from']; } if (! empty($data['created_to'])) { - $indicators[] = 'To: '.$data['created_to']; + $indicators[] = 'To : '.$data['created_to']; } if (! empty($data['sticker_master_id'])) { $itemCode = Item::find($data['sticker_master_id'])->code ?? 'Unknown'; - $indicators[] = 'Item Codes: '.$itemCode; + $indicators[] = 'Item Codes : '.$itemCode; } return $indicators; @@ -409,6 +458,7 @@ class WeightValidationResource extends Resource return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); }) ->label('Select Plant') + ->searchable() ->required() ->default(function () { return optional(WeightValidation::latest()->first())->plant_id;