components([ // ]); } public static function table(Table $table): Table { return $table ->records(function (int $page, int $recordsPerPage, array $filters) { return self::listRecords($page, $recordsPerPage, $filters); }) ->columns([ TextColumn::make('uid') ->formatStateUsing(fn ($state) => username_for_admin($state)) ->label(__('label.username')) , TextColumn::make('business_type_text') ->label(__('bonus-log.fields.business_type')) , TextColumn::make('old_total_value') ->label(__('bonus-log.fields.old_total_value')) ->formatStateUsing(fn ($state) => $state >= 0 ? number_format($state) : '-') , TextColumn::make('value') ->formatStateUsing(fn ($record) => $record->old_total_value > $record->new_total_value ? "-" . number_format($record->value) : "+" . number_format($record->value)) ->label(__('bonus-log.fields.value')) , TextColumn::make('new_total_value') ->label(__('bonus-log.fields.new_total_value')) ->formatStateUsing(fn ($state) => $state >= 0 ? number_format($state) : '-') , TextColumn::make('comment') ->label(__('label.comment')) , TextColumn::make('created_at') ->label(__('label.created_at')) , ]) ->filters([ SelectFilter::make('category') ->options(BonusLogs::listCategoryOptions(true)) ->default(BonusLogs::CATEGORY_COMMON) ->selectablePlaceholder(false) ->label(__('bonus-log.category')) , SelectFilter::make('business_type') ->options(BonusLogs::listBusinessTypeOptions()) ->label(__('bonus-log.fields.business_type')) ->searchable(true) , Filter::make('uid') ->schema([ TextInput::make('uid') ->label(__('label.username')) ->placeholder('UID') , ])->query(function (Builder $query, array $data) { return $query->when($data['uid'], fn (Builder $query, $value) => $query->where("uid", $value)); }) , ]) ->recordActions([ // Tables\Actions\EditAction::make(), // Tables\Actions\DeleteAction::make(), ]) ->toolbarActions([ // Tables\Actions\DeleteBulkAction::make(), ]); } public static function getPages(): array { return [ 'index' => ManageBonusLogs::route('/'), ]; } private static function listRecords(int $page, int $perPage, array $filters = []): LengthAwarePaginator { $rep = new BonusRepository(); $category = $filters['category']['value'] ?: BonusLogs::CATEGORY_COMMON; $userId = intval($filters['userId']['value'] ?? 0); $businessType = intval($filters['businessType']['value'] ?? 0); $list = $rep->getList($category, $userId, $businessType, $page, $perPage); $count = $rep->getCount($category, $userId, $businessType); return new LengthAwarePaginator($list, $count, $perPage, $page); } }