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;
@@ -41,42 +42,84 @@ class WeightValidationResource extends Resource
public static function form(Form $form): Form public static function form(Form $form): Form
{ {
return $form return $form
->schema([
Section::make('')
->schema([ ->schema([
Forms\Components\Select::make('plant_id') Forms\Components\Select::make('plant_id')
->label('Plant Name')
->relationship('plant', 'name') ->relationship('plant', 'name')
->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();
}) })
->columnSpan(1)
->required(), ->required(),
Forms\Components\Select::make('item_id') Forms\Components\Select::make('item_id')
->relationship('item', 'code') ->relationship('item', 'code')
->label('Item Code') ->label('Item Code')
->searchable() ->searchable()
->columnSpan(1)
->required(), ->required(),
Forms\Components\TextInput::make('obd_number') Forms\Components\TextInput::make('obd_number')
->label('OBD Number') ->label('OBD Number')
->minLength(8)
->placeholder('Scan the valid OBD Number')
->columnSpan(1)
->required(), ->required(),
Forms\Components\TextInput::make('line_number') Forms\Components\TextInput::make('line_number')
->label('Line Number') ->label('Line Number')
->minLength(1)
->integer()
->columnSpan(1)
->placeholder('Scan the valid Line Number')
->required(), ->required(),
Forms\Components\TextInput::make('batch_number') Forms\Components\TextInput::make('batch_number')
->label('Batch Number') ->label('Batch Number')
->minLength(8)
->numeric()
->columnSpan(1)
->placeholder('Scan the valid Batch Number')
->required(), ->required(),
Forms\Components\TextInput::make('obd_weight') Forms\Components\TextInput::make('obd_weight')
->label('Actual Weight') ->label('Actual Weight')
->minLength(1)
->numeric()
->columnSpan(1)
->placeholder('Scan the valid Actual Weight')
->required(), ->required(),
Forms\Components\TextInput::make('vehicle_number') Forms\Components\TextInput::make('vehicle_number')
->label('Vehicle Number'), ->label('Vehicle Number')
->minLength(10)
->columnSpan(1)
->placeholder('Scan the valid Vehicle Number'),
Forms\Components\TextInput::make('heat_number') Forms\Components\TextInput::make('heat_number')
->label('Heat Number'), ->label('Heat Number')
->minLength(4)
->columnSpan(1)
->placeholder('Scan the valid Heat Number'),
Forms\Components\TextInput::make('bundle_number') Forms\Components\TextInput::make('bundle_number')
->label('Bundle Number'), ->label('Bundle Number')
->minLength(1)
->numeric()
->columnSpan(1)
->placeholder('Scan the valid Bundle Number'),
Forms\Components\TextInput::make('picked_weight') Forms\Components\TextInput::make('picked_weight')
->label('Picked Weight'), ->label('Picked Weight')
->minLength(1)
->numeric()
->columnSpan(1)
->placeholder('Scan the valid Picked Weight'),
Forms\Components\TextInput::make('scanned_by') Forms\Components\TextInput::make('scanned_by')
->label('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;
@@ -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;