diff --git a/app/Console/Commands/Services/Tasks/GenerateDefaultSetting.php b/app/Console/Commands/Services/Tasks/GenerateDefaultSetting.php index 4d6d9602..9df054ac 100644 --- a/app/Console/Commands/Services/Tasks/GenerateDefaultSetting.php +++ b/app/Console/Commands/Services/Tasks/GenerateDefaultSetting.php @@ -79,7 +79,7 @@ class GenerateDefaultSetting Notice::note('3) comparing bookmaker', 'p'); } - $bookmakers = Bookmaker::where('is_active', 1)->pluck('id')->toArray(); + $bookmakers = Bookmaker::get(); $res = Client::get(); foreach ($res as $client) { @@ -98,19 +98,32 @@ class GenerateDefaultSetting break; } - foreach ($bookmakers as $sorting => $bookmaker_id) { + $i = 0; + foreach ($bookmakers as $bookmaker) { - $is_hidden = \in_array($bookmaker_id, $in_table_bookmaker) ? 0 : 1; + $i++; + + $is_hidden = \in_array($bookmaker->id, $in_table_bookmaker) ? 0 : 1; foreach ($client_bookmakers as $client_bookmaker_id) { - if ($client_bookmaker_id != $bookmaker_id) { + if ($client_bookmaker_id != $bookmaker->id) { - for ($method_id = 1; $method_id <= 4; $method_id++) { - ComparingBookmaker::updateOrCreate( - ['method_id' => $method_id, 'sport_id' => $sport_id, 'client_bookmaker_id' => $client_bookmaker_id, 'bookmaker_id' => $bookmaker_id], - ['is_hidden' => $is_hidden, 'is_active' => 1, 'sorting' => $sorting] - ); + if ($bookmaker->is_active) { + for ($method_id = 1; $method_id <= 4; $method_id++) { + ComparingBookmaker::updateOrCreate( + ['method_id' => $method_id, 'sport_id' => $sport_id, 'client_bookmaker_id' => $client_bookmaker_id, 'bookmaker_id' => $bookmaker->id], + ['is_hidden' => $is_hidden, 'is_active' => 1, 'time_lastcheck' => 600, 'margin_threshold' => 110, 'sorting' => $i] + ); + } + } else { + for ($method_id = 1; $method_id <= 4; $method_id++) { + ComparingBookmaker::where('method_id', $method_id) + ->where('sport_id', $sport_id) + ->where('bookmaker_id', $bookmaker->id) + ->where('client_bookmaker_id', $client_bookmaker_id) + ->delete(); + } } } } diff --git a/app/Filament/Resources/Events/Tables/EventsTable.php b/app/Filament/Resources/Events/Tables/EventsTable.php index 3a294e51..af49727a 100644 --- a/app/Filament/Resources/Events/Tables/EventsTable.php +++ b/app/Filament/Resources/Events/Tables/EventsTable.php @@ -220,7 +220,7 @@ class EventsTable ->hiddenLabel() ->preload() ->options(function () { - return Sport::query()->where('is_active', 1)->pluck('name', 'id'); + return Sport::getSportForClient(); }) ->live() ->reactive() diff --git a/app/Livewire/ComparingBookmaker/LoadBookmaker.php b/app/Livewire/ComparingBookmaker/LoadBookmaker.php new file mode 100644 index 00000000..477ef686 --- /dev/null +++ b/app/Livewire/ComparingBookmaker/LoadBookmaker.php @@ -0,0 +1,20 @@ +user()->id); + + return ComparingBookmaker::query() + ->with('bookmaker') + ->where('sport_id', $user->sport_id) + ->where('client_bookmaker_id', $user->bookmaker_id) + ->orderBy('sorting'); + } +} diff --git a/app/Livewire/ComparingBookmakerMenu.php b/app/Livewire/ComparingBookmakerMenu.php index 3911c38d..9f196cfa 100644 --- a/app/Livewire/ComparingBookmakerMenu.php +++ b/app/Livewire/ComparingBookmakerMenu.php @@ -3,24 +3,29 @@ namespace App\Livewire; use App\Filament\Tables\Columns\BookmakerIcon; +use App\Livewire\ComparingBookmaker\LoadBookmaker; use App\Models\ComparingBookmaker; use Filament\Actions\Action; use Filament\Actions\BulkAction; use Filament\Actions\BulkActionGroup; use Filament\Actions\Concerns\InteractsWithActions; use Filament\Actions\Contracts\HasActions; +use Filament\Forms\Components\Radio; use Filament\Forms\Components\TextInput; use Filament\Schemas\Concerns\InteractsWithSchemas; use Filament\Schemas\Contracts\HasSchemas; -use Filament\Tables\Columns\IconColumn; use Filament\Tables\Columns\TextColumn; +use Filament\Tables\Columns\TextInputColumn; use Filament\Tables\Columns\ToggleColumn; use Filament\Tables\Concerns\InteractsWithTable; use Filament\Tables\Contracts\HasTable; use Filament\Tables\Enums\FiltersLayout; +use Filament\Tables\Filters\Filter; +use Filament\Tables\Filters\Indicator; use Filament\Tables\Filters\TernaryFilter; use Filament\Tables\Table; use Illuminate\Contracts\View\View; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Collection; use Livewire\Component; @@ -30,8 +35,6 @@ class ComparingBookmakerMenu extends Component implements HasActions, HasSchemas use InteractsWithSchemas; use InteractsWithTable; - public $active_methode = 1; - protected $listeners = [ 'refresh' => '$refresh', ]; @@ -41,49 +44,74 @@ class ComparingBookmakerMenu extends Component implements HasActions, HasSchemas return $table ->description('') ->description('Bookmaker order is priority. Maximum time than can pass since last check or update. If older bookmaker will be ignored') - ->headerActions([ - Action::make('top') - ->color(fn () => $this->active_methode == 1 ? 'primary' : 'gray') - ->icon('phosphor-cell-signal-full') - ->action(fn () => $this->active_methode = 1) - ->after(fn () => $this->dispatch('refresh')), - Action::make('middle')->action(fn () => $this->active_methode = 2) - ->color(fn () => $this->active_methode == 2 ? 'primary' : 'gray') - ->icon('phosphor-cell-signal-high') - ->after(fn () => $this->dispatch('refresh')), - Action::make('low')->action(fn () => $this->active_methode = 3) - ->color(fn () => $this->active_methode == 3 ? 'primary' : 'gray') - ->icon('phosphor-cell-signal-medium') - ->after(fn () => $this->dispatch('refresh')), - - ]) ->reorderable('sorting') + ->reorderRecordsTriggerAction(function (Action $action) { + return $action->button(); + }) ->paginated(false) ->striped() - ->query(ComparingBookmaker::query() - ->with('bookmaker') - // ->where('is_hidden', 0) - ->where('sport_id', auth()->user()->sport_id) - ->where('client_bookmaker_id', auth()->user()->bookmaker_id) - ->where('method_id', $this->active_methode) - ->orderBy('sorting')) + ->query(LoadBookmaker::load()) ->columns([ TextColumn::make('Position') ->alignCenter() ->badge() ->rowIndex(), - // IconColumn::make('sport.icon') - // ->label('') - // ->icon(fn ($record) => $record->sport->icon) - // ->visibleFrom('lg'), + TextColumn::make('bookmaker_id')->label('Id'), BookmakerIcon::make('bookmaker.icon')->label('Icon'), - TextColumn::make('time_lastcheck')->label('Time Passed'), - TextColumn::make('margin_threshold'), + TextInputColumn::make('time_lastcheck') + ->label('Time Passed') + ->prefix('Seconds:') + ->rules(['required', 'max:200', 'min:100']), + TextInputColumn::make('margin_threshold') + ->label('Maximum Margin') + ->prefix('Threshold:') + ->rules(['required', 'max:200', 'min:100']), ToggleColumn::make('is_active'), ]) ->filters([ - TernaryFilter::make('is_active')->default(1)->label('Show active'), + Filter::make('method_id') + ->schema([ + Radio::make('method_id') + ->inline() + ->default(1) + ->label('League / Tournament Level') + ->options([ + 1 => 'TOP', + 2 => 'MIDDLE', + 3 => 'LOW', + ]), + ]) + ->query(function (Builder $query, array $data): Builder { + return $query + ->when( + $data['method_id'], + fn (Builder $query, $method_id): Builder => $query->where('method_id', $method_id), + ); + })->indicateUsing(function (array $data): array { + $indicators = []; + + if ($data['method_id'] ?? null) { + switch ($data['method_id']) { + case 1: + $indicators[] = Indicator::make('Method: TOP'); + break; + case 2: + $indicators[] = Indicator::make('Method: MIDDLE'); + break; + case 3: + $indicators[] = Indicator::make('Method: LOW'); + break; + } + } + + return $indicators; + })->columnSpan(6), + TernaryFilter::make('is_active') + ->columnSpan(2) + ->default(1) + ->label('Show active'), ], layout: FiltersLayout::AboveContent) + ->filtersFormColumns(8) ->deferFilters(false) ->toolbarActions([ BulkActionGroup::make([ @@ -99,7 +127,29 @@ class ComparingBookmakerMenu extends Component implements HasActions, HasSchemas } }) ->form([ - TextInput::make('time_lastcheck')->hiddenLabel()->prefix('Seconds'), + + TextInput::make('time_lastcheck') + ->numeric() + ->hiddenLabel() + ->prefix('Seconds'), + ]), + BulkAction::make('margin_threshold') + ->label('Maximum height of marging') + ->icon('phosphor-timer') + ->action(function (Collection $records, array $data): void { + foreach ($records as $record) { + ComparingBookmaker::where('id', '=', $record->id) + ->update( + ['margin_threshold' => $data['margin_threshold']] + ); + } + }) + ->form([ + TextInput::make('margin_threshold') + ->hiddenLabel() + ->numeric() + ->rules(['required', 'max:200', 'min:100']) + ->prefix('Threshold'), ]), BulkAction::make('Switch On') ->icon('phosphor-play') @@ -122,6 +172,51 @@ class ComparingBookmakerMenu extends Component implements HasActions, HasSchemas } }), ]), + ])->recordActions([ + Action::make('end') + ->iconButton() + ->icon('phosphor-arrow-fat-line-down') + ->tooltip('Move to the end') + ->action(function ($record) { + $res = ComparingBookmaker::where('method_id', $record->method_id) + ->where('sport_id', $record->sport_id) + ->where('client_bookmaker_id', $record->client_bookmaker_id) + ->orderBy('sorting') + ->pluck('bookmaker_id', 'id'); + $sorting = 1; + foreach ($res as $id => $bookmaker_id) { + if ($bookmaker_id == $record->bookmaker_id) { + ComparingBookmaker::where('id', $id) + ->update(['sorting' => \count($res)]); + } else { + ComparingBookmaker::where('id', $id) + ->update(['sorting' => $sorting]); + $sorting++; + } + } + }), + Action::make('start') + ->iconButton() + ->icon('phosphor-arrow-fat-line-up') + ->tooltip('Move to begining') + ->action(function ($record) { + $res = ComparingBookmaker::where('method_id', $record->method_id) + ->where('sport_id', $record->sport_id) + ->where('client_bookmaker_id', $record->client_bookmaker_id) + ->orderBy('sorting') + ->pluck('bookmaker_id', 'id'); + $sorting = 2; + foreach ($res as $id => $bookmaker_id) { + if ($bookmaker_id == $record->bookmaker_id) { + ComparingBookmaker::where('id', $id) + ->update(['sorting' => 1]); + } else { + ComparingBookmaker::where('id', $id) + ->update(['sorting' => $sorting]); + $sorting++; + } + } + }), ]); } diff --git a/app/Livewire/Mapper/LoadEvents.php b/app/Livewire/Mapper/LoadEvents.php index ac1ba061..de428f2a 100644 --- a/app/Livewire/Mapper/LoadEvents.php +++ b/app/Livewire/Mapper/LoadEvents.php @@ -9,7 +9,7 @@ use Illuminate\Support\Facades\Auth; class LoadEvents { - public static function load($search_left) + public static function load($search_left, $sport_id) { if ($search_left) { @@ -24,6 +24,7 @@ class LoadEvents $query = Event::query() ->with('home') ->with('away') + ->where('sport_id', $sport_id) ->where('starttime', '>', Carbon::now()) ->where(function ($query) use ($element_ids) { $query->orWhereIn('home_id', $element_ids)->orWhereIn('away_id', $element_ids); @@ -33,6 +34,7 @@ class LoadEvents $query = Event::query() ->with('home') ->with('away') + ->where('sport_id', $sport_id) ->where('betradar_id', 0) ->where('starttime', '>', Carbon::now()); } diff --git a/app/Livewire/MapperLeft.php b/app/Livewire/MapperLeft.php index 441879e8..97f2746f 100644 --- a/app/Livewire/MapperLeft.php +++ b/app/Livewire/MapperLeft.php @@ -42,6 +42,8 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable public $search_left = false; + public $sport_id = 0; + protected $listeners = [ 'reload_data_left' => '$refresh', ]; @@ -65,8 +67,10 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable public function table(Table $table): Table { + $this->setSportId(); + return $table - ->query(LoadEvents::load($this->search_left)) + ->query(LoadEvents::load($this->search_left, $this->sport_id)) ->columns([ MapperLeftColumn::make('left')->label(''), ]) @@ -75,44 +79,23 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable ->filters([ Filter::make('events') ->schema([ - Select::make(name: 'sport_id') - ->default(auth()->user()->sport_id) - ->prefixIcon(auth()->user()->sport->icon) - ->selectablePlaceholder(false) + Select::make('country_id') + ->placeholder('Country') ->hiddenLabel() + ->multiple() ->columnSpan(2) + ->searchable() ->preload() ->options(function () { - return Sport::query()->where('is_active', 1)->pluck('name', 'id'); + $res = Event::query()->where('sport_id', $this->sport_id)->where('betradar_id', 0)->where('starttime', '>', Carbon::now())->groupBy('country_id')->pluck('country_id')->toArray(); + + return Country::query()->whereIn('id', $res)->pluck('name', 'id'); }) ->live() ->reactive() - ->afterStateUpdated(function (callable $set, $livewire) { - - $livewire->dispatch('reload_data_left'); - $livewire->dispatch('reload_data_right'); - - $set('country_id', null); + ->afterStateUpdated(function (callable $set) { $set('competition_group_id', null); - }), - // Select::make('country_id') - // ->placeholder('Country') - // ->hiddenLabel() - // ->multiple() - // ->columnSpan(2) - // ->searchable() - // ->preload() - // ->options(function (Get $get) { - // $res = Event::query()->where('sport_id', $get('sport_id'))->where('betradar_id', 0)->where('starttime', '>', Carbon::now())->groupBy('country_id')->pluck('country_id')->toArray(); - - // return Country::query()->whereIn('id', $res)->pluck('name', 'id'); - // }) - // ->live() - // ->reactive() - // ->afterStateUpdated(function (callable $set) { - // $set('competition_group_id', null); - // }), Select::make('competition_group_id') ->placeholder('League') ->hiddenLabel() @@ -121,11 +104,11 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable ->multiple() ->searchable() ->options(function (Get $get) { - // if ($get('country_id')) { - // $res = Event::query()->where('sport_id', $get('sport_id'))->where('betradar_id', 0)->where('starttime', '>', Carbon::now())->whereIn('country_id', $get('country_id'))->groupBy('competition_group_id')->pluck('competition_group_id')->toArray(); - // } else { - // } - $res = Event::query()->where('sport_id', $get('sport_id'))->where('betradar_id', 0)->where('starttime', '>', Carbon::now())->groupBy('competition_group_id')->pluck('competition_group_id')->toArray(); + if ($get('country_id')) { + $res = Event::query()->where('sport_id', $this->sport_id)->where('betradar_id', 0)->where('starttime', '>', Carbon::now())->whereIn('country_id', $get('country_id'))->groupBy('competition_group_id')->pluck('competition_group_id')->toArray(); + } else { + $res = Event::query()->where('sport_id', $this->sport_id)->where('betradar_id', 0)->where('starttime', '>', Carbon::now())->groupBy('competition_group_id')->pluck('competition_group_id')->toArray(); + } $comps = CompetitionGroup::with('country')->whereIn('id', $res)->get(); @@ -146,11 +129,8 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable ->query(function (Builder $query, array $data): Builder { return $query ->when( - $data['sport_id'], - fn (Builder $query, $sport_id) => $query->where('sport_id', $sport_id) - // )->when( - // $data['country_id'], - // fn (Builder $query, $country_id) => $query->where('country_id', $country_id) + $data['country_id'], + fn (Builder $query, $country_id) => $query->where('country_id', $country_id) )->when( $data['competition_group_id'], fn (Builder $query, $competition_group_id) => $query->whereIn('competition_group_id', $competition_group_id) @@ -192,6 +172,11 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable $this->elements_swopped = ! $this->elements_swopped; } + public function setSportId() + { + $this->sport_id = Sport::getSportId(); + } + #[On('search_left')] public function searchLeft($str) { diff --git a/app/Livewire/TopMenuItems.php b/app/Livewire/TopMenuItems.php index fd51157f..c2cb022f 100644 --- a/app/Livewire/TopMenuItems.php +++ b/app/Livewire/TopMenuItems.php @@ -2,6 +2,7 @@ namespace App\Livewire; +use App\Models\Sport; use App\Models\User; use Illuminate\Support\Facades\Route; use Livewire\Component; @@ -15,14 +16,24 @@ class TopMenuItems extends Component 'reload_data_right' => '$refresh', ]; + protected string $sport = ''; + public function mount() { $this->current = Route::currentRouteName(); + + } + + public function setUser() + { + $user = User::find(auth()->user()->id); + + $this->sport = Sport::where('id', $user->sport_id)->value('name'); } public function render() { - return view('livewire.top-menu-items'); + return view('livewire.top-menu-items', ['sport' => $this->sport]); } public function swopBookmaker($bookmaker_id) diff --git a/app/Models/Sport.php b/app/Models/Sport.php index 75ff0b1e..baf71861 100644 --- a/app/Models/Sport.php +++ b/app/Models/Sport.php @@ -27,4 +27,22 @@ class Sport extends Model } } } + + public static function getSportForClient() + { + $user = User::find(auth()->user()->id); + + $sports = Client::where('id', $user->client_id)->value('sport'); + + return Sport::query()->whereIn('id', $sports)->pluck('name', 'id'); + + } + + public static function getSportId() + { + $user = User::find(auth()->user()->id); + + return $user->sport_id; + + } } diff --git a/composer.lock b/composer.lock index f8235549..e9a66aeb 100644 --- a/composer.lock +++ b/composer.lock @@ -12814,12 +12814,12 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": [], "prefer-stable": true, "prefer-lowest": false, "platform": { "php": "^8.3" }, - "platform-dev": {}, - "plugin-api-version": "2.9.0" + "platform-dev": [], + "plugin-api-version": "2.6.0" } diff --git a/database/migrations/2026_01_17_163643_create_comparing_bookmakers_table.php b/database/migrations/2026_01_17_163643_create_comparing_bookmakers_table.php index f46a3284..ff404654 100644 --- a/database/migrations/2026_01_17_163643_create_comparing_bookmakers_table.php +++ b/database/migrations/2026_01_17_163643_create_comparing_bookmakers_table.php @@ -17,8 +17,8 @@ return new class extends Migration $table->integer('sport_id')->index()->references('id')->on('sports'); $table->integer('bookmaker_id')->index()->references('id')->on('bookmakers'); $table->integer('client_bookmaker_id')->index()->references('id')->on('bookmakers'); - $table->integer('time_lastcheck'); - $table->decimal('margin_threshold', 3, 2)->default(0); + $table->integer('time_lastcheck')->default(0); + $table->integer('margin_threshold')->default(0); $table->boolean('is_active')->default(false); $table->boolean('is_hidden')->default(false); $table->integer('sorting')->nullable()->default(0); diff --git a/resources/views/livewire/top-menu-items.blade.php b/resources/views/livewire/top-menu-items.blade.php index e943f2bf..74e4ead8 100644 --- a/resources/views/livewire/top-menu-items.blade.php +++ b/resources/views/livewire/top-menu-items.blade.php @@ -190,13 +190,13 @@ - - Comparing Bookmaker + Comparing Bookmaker {{ $sport }} @livewire('comparing-bookmaker-menu')