Added report filter functionality and removed reader_code on report
This commit is contained in:
@@ -14,9 +14,11 @@ use App\Models\Plant;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
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\Tabs\Tab;
|
use Filament\Forms\Components\Tabs\Tab;
|
||||||
|
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;
|
||||||
@@ -24,6 +26,7 @@ use Filament\Resources\Resource;
|
|||||||
use Filament\Tables;
|
use Filament\Tables;
|
||||||
use Filament\Tables\Actions\ExportAction;
|
use Filament\Tables\Actions\ExportAction;
|
||||||
use Filament\Tables\Actions\ImportAction;
|
use Filament\Tables\Actions\ImportAction;
|
||||||
|
use Filament\Tables\Filters\Filter;
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
@@ -56,6 +59,7 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
if (!$plantId) {
|
if (!$plantId) {
|
||||||
|
// $set('gPePlantError', 'Please select a plant first.');
|
||||||
$set('gPePlantError', 'Please select a plant first.');
|
$set('gPePlantError', 'Please select a plant first.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -239,11 +243,11 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
->alignCenter()
|
->alignCenter()
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('reader_code')
|
// Tables\Columns\TextColumn::make('reader_code')
|
||||||
->label('Reader Code')
|
// ->label('Reader Code')
|
||||||
->alignCenter()
|
// ->alignCenter()
|
||||||
->searchable()
|
// ->searchable()
|
||||||
->sortable(),
|
// ->sortable(),
|
||||||
Tables\Columns\TextColumn::make('patrol_time')
|
Tables\Columns\TextColumn::make('patrol_time')
|
||||||
->label('Patrol Time')
|
->label('Patrol Time')
|
||||||
->dateTime()
|
->dateTime()
|
||||||
@@ -277,7 +281,121 @@ class GuardPatrolEntryResource extends Resource
|
|||||||
])
|
])
|
||||||
->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('Guard Name')
|
||||||
|
->label('Search by Guard Name')
|
||||||
|
->options(function (callable $get) {
|
||||||
|
$plantId = $get('Plant');
|
||||||
|
if (!$plantId) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return GuardName::where('plant_id', $plantId)->pluck('name', 'id')->toArray();
|
||||||
|
})
|
||||||
|
->searchable()
|
||||||
|
->reactive(),
|
||||||
|
Select::make('Check Point Name')
|
||||||
|
->label('Search by Check Point Name')
|
||||||
|
->options(function (callable $get) {
|
||||||
|
$plantId = $get('Plant');
|
||||||
|
if (!$plantId) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return CheckPointName::where('plant_id', $plantId)->pluck('name', 'id')->toArray();
|
||||||
|
})
|
||||||
|
->searchable()
|
||||||
|
->reactive(),
|
||||||
|
TextInput::make('Created By')
|
||||||
|
->label('Created By')
|
||||||
|
->placeholder('Enter Created By'),
|
||||||
|
DateTimePicker::make(name: 'From Patrol Time')
|
||||||
|
->label('From Patrol Time')
|
||||||
|
->beforeOrEqual('To Patrol Time')
|
||||||
|
->placeholder(placeholder: 'Select From Patrol Time')
|
||||||
|
->reactive()
|
||||||
|
->native(false),
|
||||||
|
DateTimePicker::make('To Patrol Time')
|
||||||
|
->label('To Patrol Time')
|
||||||
|
->afterOrEqual('From Patrol Time')
|
||||||
|
->placeholder(placeholder: 'Select To Patrol Time')
|
||||||
|
->reactive()
|
||||||
|
->native(false),
|
||||||
])
|
])
|
||||||
|
->query(function ($query, array $data) {
|
||||||
|
//Hide all records initially if no filters are applied
|
||||||
|
if (empty($data['Plant']) && empty($data['Guard Name']) && empty($data['Check Point Name']) && empty($data['Created By']) && empty($data['From Patrol Time']) && empty($data['To Patrol Time'])) {
|
||||||
|
return $query->whereRaw('1 = 0');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Plant'])) {
|
||||||
|
$query->where('plant_id', $data['Plant']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Guard Name'])) {
|
||||||
|
$query->where('guard_name_id', $data['Guard Name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Check Point Name'])) {
|
||||||
|
$query->where('check_point_name_id', $data['Check Point Name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Created By'])) {
|
||||||
|
$query->where('created_by', $data['Created By']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['From Patrol Time'])) {
|
||||||
|
$query->where('patrol_time', '>=', $data['From Patrol Time']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['To Patrol Time'])) {
|
||||||
|
$query->where('patrol_time', '<=', $data['To Patrol Time']);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
->indicateUsing(function (array $data) {
|
||||||
|
$indicators = [];
|
||||||
|
|
||||||
|
if (!empty($data['Plant'])) {
|
||||||
|
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Guard Name'])) {
|
||||||
|
$indicators[] = 'Guard Name: ' . GuardName::where('plant_id', $data['Plant'])->where('id', $data['Guard Name'])->value('name');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Check Point Name'])) {
|
||||||
|
$indicators[] = 'Check Point Name: ' . CheckPointName::where('plant_id', $data['Plant'])->where('id', $data['Check Point Name'])->value('name');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Created By'])) {
|
||||||
|
$indicators[] = 'Created By: ' . $data['Created By'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['From Patrol Time'])) {
|
||||||
|
$indicators[] = 'From: ' . $data['From Patrol Time'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['To Patrol Time'])) {
|
||||||
|
$indicators[] = 'To: ' . $data['To Patrol Time'];
|
||||||
|
}
|
||||||
|
|
||||||
|
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