Added filter functionality
This commit is contained in:
@@ -7,13 +7,18 @@ use App\Filament\Imports\WeightValidationImporter;
|
|||||||
use App\Filament\Resources\WeightValidationResource\Pages;
|
use App\Filament\Resources\WeightValidationResource\Pages;
|
||||||
use App\Filament\Resources\WeightValidationResource\RelationManagers;
|
use App\Filament\Resources\WeightValidationResource\RelationManagers;
|
||||||
use App\Models\Item;
|
use App\Models\Item;
|
||||||
|
use App\Models\Line;
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
|
use App\Models\QualityValidation;
|
||||||
|
use App\Models\StickerMaster;
|
||||||
use App\Models\WeightValidation;
|
use App\Models\WeightValidation;
|
||||||
use Filament\Actions\Action;
|
use Filament\Actions\Action;
|
||||||
use Filament\Facades\Filament;
|
use Filament\Facades\Filament;
|
||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
|
use Filament\Forms\Components\DateTimePicker;
|
||||||
use Filament\Forms\Components\FileUpload;
|
use Filament\Forms\Components\FileUpload;
|
||||||
use Filament\Forms\Components\Select;
|
use Filament\Forms\Components\Select;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
use Filament\Forms\Get;
|
use Filament\Forms\Get;
|
||||||
use Filament\Notifications\Notification;
|
use Filament\Notifications\Notification;
|
||||||
@@ -28,6 +33,7 @@ use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Maatwebsite\Excel\Facades\Excel;
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
use Str;
|
use Str;
|
||||||
|
use Filament\Tables\Filters\Filter;
|
||||||
|
|
||||||
class WeightValidationResource extends Resource
|
class WeightValidationResource extends Resource
|
||||||
{
|
{
|
||||||
@@ -147,9 +153,209 @@ class WeightValidationResource extends Resource
|
|||||||
->sortable()
|
->sortable()
|
||||||
->toggleable(isToggledHiddenByDefault: true),
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
])
|
])
|
||||||
|
// ->filters([
|
||||||
|
// Tables\Filters\TrashedFilter::make(),
|
||||||
|
// ])
|
||||||
->filters([
|
->filters([
|
||||||
Tables\Filters\TrashedFilter::make(),
|
Tables\Filters\TrashedFilter::make(),
|
||||||
|
Filter::make('advanced_filters')
|
||||||
|
->label('Advanced Filters')
|
||||||
|
->form([
|
||||||
|
Select::make('Plant')
|
||||||
|
->label('Select Plant')
|
||||||
|
->nullable()
|
||||||
|
->options(function () {
|
||||||
|
return Plant::pluck('name', 'id');
|
||||||
|
})
|
||||||
|
->reactive(),
|
||||||
|
// ->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
|
// $set('sticker_master_id', null);
|
||||||
|
// $set('sap_msg_status', 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');
|
||||||
|
})
|
||||||
|
->searchable()
|
||||||
|
->reactive(),
|
||||||
|
TextInput::make('Obd Number')
|
||||||
|
->label('OBD Number')
|
||||||
|
->placeholder('Enter OBD Number'),
|
||||||
|
|
||||||
|
Select::make('Line')
|
||||||
|
->label('Line')
|
||||||
|
->options(function (callable $get) {
|
||||||
|
$plantId = $get('Plant');
|
||||||
|
|
||||||
|
if (!$plantId) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get unique line_numbers for the selected plant_id
|
||||||
|
return WeightValidation::where('plant_id', $plantId)
|
||||||
|
->distinct()
|
||||||
|
->orderBy('line_number')
|
||||||
|
->pluck('line_number', 'line_number')
|
||||||
|
->toArray();
|
||||||
|
})
|
||||||
|
->reactive(),
|
||||||
|
|
||||||
|
TextInput::make('Batch')
|
||||||
|
->label('Batch Number')
|
||||||
|
->placeholder('Enter Batch Number'),
|
||||||
|
|
||||||
|
TextInput::make('Actual Weight')
|
||||||
|
->label('Actual Weight')
|
||||||
|
->placeholder('Enter Actual Weight'),
|
||||||
|
|
||||||
|
TextInput::make('Vehicle Number')
|
||||||
|
->label('Vehicle Number')
|
||||||
|
->placeholder('Enter Vehicle Number'),
|
||||||
|
|
||||||
|
TextInput::make('Heat Number')
|
||||||
|
->label('Heat Number')
|
||||||
|
->placeholder('Enter Heat Number'),
|
||||||
|
|
||||||
|
TextInput::make('Bundle Number')
|
||||||
|
->label('Bundle Number')
|
||||||
|
->placeholder('Enter Bundle Number'),
|
||||||
|
|
||||||
|
TextInput::make('Scanned By')
|
||||||
|
->label('Scanned By')
|
||||||
|
->placeholder('Enter Scanned By'),
|
||||||
|
|
||||||
|
DateTimePicker::make(name: 'created_from')
|
||||||
|
->label('Created From')
|
||||||
|
->placeholder(placeholder: 'Select From DateTime')
|
||||||
|
->reactive()
|
||||||
|
->native(false),
|
||||||
|
DateTimePicker::make('created_to')
|
||||||
|
->label('Created To')
|
||||||
|
->placeholder(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['Line']) && empty($data['Obd Number']) && empty($data['Batch']) && empty($data['Actual Weight']) && empty($data['Vehicle Number']) && empty($data['Heat Number']) && empty($data['Bundle Number']) && empty($data['Scanned By']) && empty($data['created_from']) && empty($data['created_to'])) {
|
||||||
|
return $query->whereRaw('1 = 0');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Plant'])) {
|
||||||
|
$query->where('plant_id', $data['Plant']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Item Code'])) {
|
||||||
|
$query->where('item_id', $data['Item Code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Line'])) {
|
||||||
|
$query->where('line_number', $data['Line']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Obd Number'])) {
|
||||||
|
$query->where('obd_number', $data['Obd Number']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Batch'])) {
|
||||||
|
$query->where('batch_number', $data['Batch']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Actual Weight'])) {
|
||||||
|
$query->where('actual_weight', $data['Actual Weight']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Vehicle Number'])) {
|
||||||
|
$query->where('vehicle_number',$data['Vehicle Number']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Heat Number'])) {
|
||||||
|
$query->where('heat_number',$data['Heat Number']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Bundle Number'])) {
|
||||||
|
$query->where('bundle_number',$data['Bundle Number']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Scanned By'])) {
|
||||||
|
$query->where('scanned_by', $data['Scanned By']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!empty($data['created_from'])) {
|
||||||
|
$query->where('created_at', '>=', $data['created_from']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['created_to'])) {
|
||||||
|
$query->where('created_at', '<=', $data['created_to']);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
->indicateUsing(function (array $data) {
|
||||||
|
$indicators = [];
|
||||||
|
|
||||||
|
if (!empty($data['Plant'])) {
|
||||||
|
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Item Code'])) {
|
||||||
|
$indicators[] = 'Item Code: ' . $data['Item Code'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Line'])) {
|
||||||
|
$indicators[] = 'Line: ' . $data['Line'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Obd Number'])) {
|
||||||
|
$indicators[] = 'OBD Number: ' . $data['Obd Number'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Batch'])) {
|
||||||
|
$indicators[] = 'Batch Number: ' . $data['Batch'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Actual Weight'])) {
|
||||||
|
$indicators[] = 'Actual Weight: ' . $data['Actual Weight'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Vehicle Number'])) {
|
||||||
|
$indicators[] = 'Vehicle Number: ' . $data['Vehicle Number'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Heat Number'])) {
|
||||||
|
$indicators[] = 'Heat Number: ' . $data['Heat Number'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Bundle Number'])) {
|
||||||
|
$indicators[] = 'Bundle Number: ' . $data['Bundle Number'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Scanned By'])) {
|
||||||
|
$indicators[] = 'Scanned By: ' . $data['Scanned By'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['created_from'])) {
|
||||||
|
$indicators[] = 'From: ' . $data['created_from'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($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;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $indicators;
|
||||||
|
})
|
||||||
])
|
])
|
||||||
|
->filtersFormMaxHeight('280px')
|
||||||
->actions([
|
->actions([
|
||||||
Tables\Actions\ViewAction::make(),
|
Tables\Actions\ViewAction::make(),
|
||||||
Tables\Actions\EditAction::make(),
|
Tables\Actions\EditAction::make(),
|
||||||
|
|||||||
Reference in New Issue
Block a user