Updated design, validation, and filters
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Gemini PR Review / Gemini PR Review (pull_request) Has been cancelled
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Has been cancelled
Laravel Larastan / larastan (pull_request) Has been cancelled
Laravel Pint / pint (pull_request) Has been cancelled

This commit is contained in:
dhanabalan
2026-04-29 18:15:28 +05:30
parent 1779271c1a
commit a3561aa301

View File

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