label('Home')->url(route('filament.pages.home')), ]; } // Specify model used protected function getTableQuery(): Builder { return MaintenanceSchedule::query(); } // Specify function call on clicking table row // protected function getTableRecordUrlUsing(): ?Closure // { // return fn ($record) => $this->record = $record; // // return fn ($record) => VehicleResource::getUrl('vehicle-usage', ['record' => $record->vehicle_id]); // } // protected function getTableRecordActionUsing(): ?Closure // { // return fn ($record) => $this->record = $record; // } // Specify filters appearance protected function getTableFiltersFormColumns(): int|array { return 3; } // Specify filters layout protected function getTableFiltersLayout(): ?string { return Layout::AboveContent; } protected function getTableHeading(): string|Htmlable|Closure|null { return 'Je ziet hier welk voe- of werktuig wat, wanneer en waar gedaan heeft'; } // Specify filters protected function getTableFilters(): array { return [ Filter::make('complex_filters')->columnSpan(4) ->form([ Wizard::make([ Step::make('Filters') ->label(__('region-resource.filters')) ->schema([ Card::make([ Select::make('windrichting') ->label('Windrichting') ->options(Region::where('region_type_id', RegionType::where('external_identifier', config('regions.amsterdam.wind-district_type'))->pluck('id'))->get()->pluck('name', 'id'))->reactive()->afterStateUpdated(fn (callable $set) => $set('sportpark', null)), Select::make('sportpark') ->label('Sportpark') ->multiple() ->options(function (Closure $get) { if ($get('windrichting') == null) return Region::where('region_type_id', RegionType::where('external_identifier', config('regions.amsterdam.sportspark_type'))->pluck('id'))->get()->pluck('name', 'id'); return Region::where('parent_region_id', $get('windrichting'))->pluck('name', 'id'); })->preload() ->searchable(), Select::make('vehicle_id') ->label('Voertuig') ->multiple() ->options(Vehicle::all()->pluck('name', 'id'))->preload() ->searchable(), Card::make()->columns(2)->schema([ // TODO: (could have) Add validation DatePicker::make('start_date')->label('Startdatum') ->minDate(now()->subYears(10)) ->maxDate(now()), DatePicker::make('end_date')->label('Einddatum') ->minDate(now()->subYears(10)) ->maxDate(now()) ]) ])->label(__('region-resource.organizing')), ]), ]), ]) ->query(function (Builder $query, array $data): Builder { // Filter on sportparks if (@$data['sportpark']) $query = $query->whereHas('region', function (Builder $query) use ($data) { $query->whereIn('parent_region_id', $data['sportpark']); }); else { // Makes sure that if filter is empty no records are shown $query->whereRaw('1 = 0'); } // Filter on vehicle if (@$data['vehicle_id']) { $this->record = Vehicle::find($data['vehicle_id'][0]); $query = $query->whereIn('vehicle_id', $data['vehicle_id']); // dd($this->record->id); } else { $this->record = null; // Makes sure that if filter is empty no records are shown $query->whereRaw('1 = 0'); } if (@$data['start_date']) $query = $query->whereDate('start_at', ">=", $data['start_date']); //->where('id', ">=", $data['min']); if (strlen(@$data['end_date'])) $query = $query->whereDate('end_at', "<=", $data['end_date']); //->where('id', ">=", $data['max']); return $query; }) ]; } // Specifiy columns to be displayed protected function getTableColumns(): array { return [ TextColumn::make('vehicle.name')->label(__('vehicle-resource.name'))->sortable(), TextColumn::make('start_at') ->date()->label(__('maintenance-schedules-resource.date'))->sortable(), TextColumn::make('start_at_time')->label(__('maintenance-schedules-resource.time')) ->getStateUsing(fn (MaintenanceSchedule $record) => $record->start_at)->time('H:i')->sortable(['start_at']), TextColumn::make('duration')->label(__('maintenance-schedules-resource.duration'))->suffix(' min'), TextColumn::make('region.name')->label(__('region-resource.sportsfield'))->sortable(), TextColumn::make('maintenanceOperation.name')->label(__('maintenance-operation-resource.maintenance_operation'))->sortable(), TextColumn::make('werktuig')->label('Werktuig')->sortable(), BadgeColumn::make('is_completed')->label('Opmerking')->enum([ false => 'nog niet gereed', true => 'gereed', ])->colors([ 'primary', 'warning' => false, 'success' => true, ]) ]; } // TODO: Specify width of columns protected function getFooterWidgets(): array { // dd($this->record); if ($this->record != null) return [CustomUsageWidget::class]; return []; } }