Merge pull request 'Added filter logic in import transit resource page' (#761) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 23s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 23s
Reviewed-on: #761
This commit was merged in pull request #761.
This commit is contained in:
@@ -24,6 +24,10 @@ use Illuminate\Support\Facades\DB;
|
|||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Maatwebsite\Excel\Facades\Excel;
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
use Filament\Tables\Actions\ImportAction;
|
use Filament\Tables\Actions\ImportAction;
|
||||||
|
use Filament\Forms\Components\DateTimePicker;
|
||||||
|
use Filament\Forms\Components\Select;
|
||||||
|
use Filament\Tables\Filters\Filter;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
// use PhpOffice\PhpSpreadsheet\IOFactory;
|
// use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
class ImportTransitResource extends Resource
|
class ImportTransitResource extends Resource
|
||||||
@@ -402,7 +406,100 @@ class ImportTransitResource extends Resource
|
|||||||
])
|
])
|
||||||
->filters([
|
->filters([
|
||||||
Tables\Filters\TrashedFilter::make(),
|
Tables\Filters\TrashedFilter::make(),
|
||||||
|
Filter::make('advanced_filters')
|
||||||
|
->label('Advanced Filters')
|
||||||
|
->form([
|
||||||
|
TextInput::make('cri_rfq_number')
|
||||||
|
->label('CRI RFQ Number')
|
||||||
|
->reactive()
|
||||||
|
->placeholder('Enter Rfq Number')
|
||||||
|
->afterStateUpdated(function ($state, callable $set, callable $get): void {
|
||||||
|
$set('created_from', null);
|
||||||
|
$set('created_to', null);
|
||||||
|
}),
|
||||||
|
TextInput::make('status')
|
||||||
|
->label('Status')
|
||||||
|
->reactive()
|
||||||
|
->placeholder('Enter Status')
|
||||||
|
->afterStateUpdated(function ($state, callable $set, callable $get): void {
|
||||||
|
$set('created_from', null);
|
||||||
|
$set('created_to', null);
|
||||||
|
}),
|
||||||
|
Select::make('is_transit_identified')
|
||||||
|
->label('Is Transit Identified')
|
||||||
|
->reactive()
|
||||||
|
->options([
|
||||||
|
0 => 0,
|
||||||
|
1 => 1,
|
||||||
|
])
|
||||||
|
->afterStateUpdated(function ($state, callable $set, callable $get): void {
|
||||||
|
$set('created_from', null);
|
||||||
|
$set('created_to', null);
|
||||||
|
}),
|
||||||
|
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['cri_rfq_number']) && empty($data['status']) && ! isset($data['is_transit_identified']) && empty($data['created_from']) && empty($data['created_to'])) {
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['cri_rfq_number'])) {
|
||||||
|
$query->where('cri_rfq_number', 'like', '%'.$data['cri_rfq_number'].'%');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['status'])) {
|
||||||
|
$query->where('status', 'like', '%'.$data['status'].'%');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($data['is_transit_identified'])) {
|
||||||
|
$query->where('is_transit_identified', $data['is_transit_identified']);
|
||||||
|
}
|
||||||
|
|
||||||
|
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['cri_rfq_number'])) {
|
||||||
|
$indicators[] = 'CRI Rfq Number: '.$data['cri_rfq_number'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['status'])) {
|
||||||
|
$indicators[] = 'Status: '.$data['status'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($data['is_transit_identified'])) {
|
||||||
|
$indicators[] = 'Is Transit Identified: '.$data['is_transit_identified'];
|
||||||
|
}
|
||||||
|
|
||||||
|
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([
|
->actions([
|
||||||
Tables\Actions\ViewAction::make(),
|
Tables\Actions\ViewAction::make(),
|
||||||
Tables\Actions\EditAction::make(),
|
Tables\Actions\EditAction::make(),
|
||||||
|
|||||||
Reference in New Issue
Block a user