Added filter functionality in pallet validation page
This commit is contained in:
@@ -6,7 +6,10 @@ use App\Filament\Exports\PalletValidationExporter;
|
|||||||
use App\Filament\Imports\PalletValidationImporter;
|
use App\Filament\Imports\PalletValidationImporter;
|
||||||
use App\Filament\Resources\PalletValidationResource\Pages;
|
use App\Filament\Resources\PalletValidationResource\Pages;
|
||||||
use App\Filament\Resources\PalletValidationResource\RelationManagers;
|
use App\Filament\Resources\PalletValidationResource\RelationManagers;
|
||||||
|
use App\Models\Item;
|
||||||
use App\Models\PalletValidation;
|
use App\Models\PalletValidation;
|
||||||
|
use App\Models\Plant;
|
||||||
|
use App\Models\StickerMaster;
|
||||||
use Filament\Facades\Filament;
|
use Filament\Facades\Filament;
|
||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
use Filament\Forms\Components\Section;
|
use Filament\Forms\Components\Section;
|
||||||
@@ -22,6 +25,10 @@ use Filament\Tables\Actions\ExportAction;
|
|||||||
use Filament\Tables\Actions\ImportAction;
|
use Filament\Tables\Actions\ImportAction;
|
||||||
use Log;
|
use Log;
|
||||||
use Filament\Tables\Actions\Action;
|
use Filament\Tables\Actions\Action;
|
||||||
|
use Filament\Forms\Components\DateTimePicker;
|
||||||
|
use Filament\Tables\Filters\Filter;
|
||||||
|
use Filament\Forms\Components\Select;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
|
||||||
|
|
||||||
class PalletValidationResource extends Resource
|
class PalletValidationResource extends Resource
|
||||||
@@ -31,7 +38,6 @@ class PalletValidationResource extends Resource
|
|||||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||||
protected static ?string $navigationGroup = 'Export Dispatch';
|
protected static ?string $navigationGroup = 'Export Dispatch';
|
||||||
|
|
||||||
|
|
||||||
public static function form(Form $form): Form
|
public static function form(Form $form): Form
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -179,7 +185,6 @@ class PalletValidationResource extends Resource
|
|||||||
// ->label('ID')
|
// ->label('ID')
|
||||||
// ->numeric()
|
// ->numeric()
|
||||||
// ->sortable(),
|
// ->sortable(),
|
||||||
|
|
||||||
Tables\Columns\TextColumn::make('No.')
|
Tables\Columns\TextColumn::make('No.')
|
||||||
->label('No.')
|
->label('No.')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
@@ -250,9 +255,226 @@ class PalletValidationResource 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): void {
|
||||||
|
$set('pallet_number', null);
|
||||||
|
$set('serial_number', null);
|
||||||
|
$set('pallet_status', null);
|
||||||
|
$set('locator_number', null);
|
||||||
|
$set('locator_quantity', null);
|
||||||
|
$set('created_from', null);
|
||||||
|
$set('created_to', null);
|
||||||
|
$set('created_by', null);
|
||||||
|
$set('scanned_from', null);
|
||||||
|
$set('scanned_to', null);
|
||||||
|
$set('scanned_by', null);
|
||||||
|
}),
|
||||||
|
Select::make('pallet_number')
|
||||||
|
->label('Pallet Number')
|
||||||
|
->options(function (callable $get) {
|
||||||
|
$plantId = $get('Plant');
|
||||||
|
if (!$plantId) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return PalletValidation::where('plant_id', $plantId)
|
||||||
|
->whereNotNull('pallet_number')
|
||||||
|
->where('pallet_number','!=', '')
|
||||||
|
->orderBy('pallet_number', 'asc')
|
||||||
|
->get()
|
||||||
|
->unique('pallet_number')
|
||||||
|
->pluck('pallet_number', 'id')
|
||||||
|
->toArray();
|
||||||
|
})
|
||||||
|
->searchable()
|
||||||
|
->reactive(),
|
||||||
|
TextInput::make('serial_number')
|
||||||
|
->label('Serial Number')
|
||||||
|
->placeholder(placeholder: 'Enter Serial Number'),
|
||||||
|
Select::make('pallet_status')
|
||||||
|
->label('Pallet Status')
|
||||||
|
->options([
|
||||||
|
'Completed' => 'Completed',
|
||||||
|
]),
|
||||||
|
Select::make('locator_number')
|
||||||
|
->label('Locator Number')
|
||||||
|
->options(function (callable $get) {
|
||||||
|
$plantId = $get('Plant');
|
||||||
|
if (!$plantId) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return PalletValidation::where('plant_id', $plantId)
|
||||||
|
->whereNotNull('locator_number')
|
||||||
|
->where('locator_number','!=', '')
|
||||||
|
->orderBy('locator_number', 'asc')
|
||||||
|
->get()
|
||||||
|
->unique('locator_number')
|
||||||
|
->pluck('locator_number', 'id')
|
||||||
|
->toArray();
|
||||||
|
})
|
||||||
|
->searchable()
|
||||||
|
->reactive(),
|
||||||
|
Select::make('locator_quantity')
|
||||||
|
->label('Locator Quantity')
|
||||||
|
->options([
|
||||||
|
0 => 0,
|
||||||
|
1 => '1',
|
||||||
|
2 => '2',
|
||||||
|
])
|
||||||
|
->reactive(),
|
||||||
|
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),
|
||||||
|
TextInput::make('created_by')
|
||||||
|
->label('Created By')
|
||||||
|
->placeholder(placeholder: 'Enter Created By'),
|
||||||
|
DateTimePicker::make(name: 'scanned_from')
|
||||||
|
->label('Scanned From')
|
||||||
|
->placeholder(placeholder: 'Select From DateTime')
|
||||||
|
->reactive()
|
||||||
|
->native(false),
|
||||||
|
DateTimePicker::make('scanned_to')
|
||||||
|
->label('Scanned To')
|
||||||
|
->placeholder(placeholder: 'Select To DateTime')
|
||||||
|
->reactive()
|
||||||
|
->native(false),
|
||||||
|
TextInput::make('scanned_by')
|
||||||
|
->label('Scanned By')
|
||||||
|
->placeholder(placeholder: 'Enter Scanned By'),
|
||||||
|
])
|
||||||
|
->query(function ($query, array $data) {
|
||||||
|
// Hide all records initially if no filters are applied
|
||||||
|
if (empty($data['Plant']) && empty($data['pallet_number']) && empty($data['serial_number']) && empty($data['pallet_status']) && empty($data['locator_number']) && empty($data['locator_quantity']) && empty($data['created_from']) && empty($data['created_to']) && empty($data['created_by']) && empty($data['scanned_from']) && empty($data['scanned_to']) && empty($data['scanned_by'])) {
|
||||||
|
return $query->whereRaw('1 = 0');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Plant'])) { //$plant = $data['Plant'] ?? null
|
||||||
|
$query->where('plant_id', $data['Plant']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['pallet_number'])) {
|
||||||
|
$query->where('pallet_number', $data['pallet_number']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['serial_number'])) {
|
||||||
|
$query->where('serial_number', $data['serial_number']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['pallet_status'])) {
|
||||||
|
$query->where('pallet_status', $data['pallet_status']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['locator_number'])) {
|
||||||
|
$query->where('locator_number', $data['locator_number']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (!empty($data['locator_quantity'])) {
|
||||||
|
// $query->where('locator_quantity', $data['locator_quantity']);
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (isset($data['locator_quantity']) && $data['locator_quantity'] != '') {
|
||||||
|
$query->where('locator_quantity', (int)$data['locator_quantity']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['created_from'])) {
|
||||||
|
$query->where('created_at', '>=', $data['created_from']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['created_to'])) {
|
||||||
|
$query->where('created_at', '<=', $data['created_to']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['created_by'])) {
|
||||||
|
$query->where('created_by', $data['created_by']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['scanned_from'])) {
|
||||||
|
$query->where('scanned_at', '>=', $data['scanned_from']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['scanned_to'])) {
|
||||||
|
$query->where('scanned_at', '<=', $data['scanned_to']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['scanned_by'])) {
|
||||||
|
$query->where('scanned_by', $data['scanned_by']);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
->indicateUsing(function (array $data) {
|
||||||
|
$indicators = [];
|
||||||
|
|
||||||
|
if (!empty($data['Plant'])) {
|
||||||
|
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['pallet_number'])) {
|
||||||
|
$indicators[] = 'Pallet Number: ' . $data['pallet_number'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['serial_number'])) {
|
||||||
|
$indicators[] = 'Serial Number: ' . $data['serial_number'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['pallet_status'])) {
|
||||||
|
$indicators[] = 'Pallet Status: ' . $data['pallet_status'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['locator_number'])) {
|
||||||
|
$indicators[] = 'Locator Number: ' . $data['locator_number'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (!empty($data['locator_quantity'])) {
|
||||||
|
// $indicators[] = 'Locator Quantity: ' . $data['locator_quantity'];
|
||||||
|
// }
|
||||||
|
if (isset($data['locator_quantity']) && $data['locator_quantity'] !== '') {
|
||||||
|
$indicators[] = 'Locator Quantity: ' . $data['locator_quantity'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['created_from'])) {
|
||||||
|
$indicators[] = 'From: ' . $data['created_from'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['created_to'])) {
|
||||||
|
$indicators[] = 'To: ' . $data['created_to'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['created_by'])) {
|
||||||
|
$indicators[] = 'Created By: ' . $data['created_by'];
|
||||||
|
}
|
||||||
|
if (!empty($data['scanned_from'])) {
|
||||||
|
$indicators[] = 'Scanned From: ' . $data['scanned_from'];
|
||||||
|
}
|
||||||
|
if (!empty($data['scanned_to'])) {
|
||||||
|
$indicators[] = 'Scanned To: ' . $data['scanned_to'];
|
||||||
|
}
|
||||||
|
if (!empty($data['scanned_by'])) {
|
||||||
|
$indicators[] = 'Scanned By: ' . $data['scanned_by'];
|
||||||
|
}
|
||||||
|
|
||||||
|
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