317 lines
14 KiB
PHP
317 lines
14 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Events\Tables;
|
|
|
|
use App\Filament\Tables\Columns\Column3way;
|
|
use App\Filament\Tables\Columns\ColumnDc;
|
|
use App\Filament\Tables\Columns\ColumnDnb;
|
|
use App\Filament\Tables\Columns\ColumnGgng;
|
|
use App\Filament\Tables\Columns\ColumnTotal;
|
|
use App\Filament\Tables\Columns\ColumnTq;
|
|
use App\Filament\Tables\Columns\MatchIds;
|
|
use App\Models\BettypeUser;
|
|
use App\Models\Country;
|
|
use App\Models\Event;
|
|
use App\Models\MultilineClient;
|
|
use CodeWithKyrian\FilamentDateRange\Forms\Components\DateRangePicker;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\ActionGroup;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Schemas\Components\Utilities\Get;
|
|
use Filament\Support\Enums\FontWeight;
|
|
use Filament\Support\Enums\VerticalAlignment;
|
|
use Filament\Tables\Columns\IconColumn;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Enums\FiltersLayout;
|
|
use Filament\Tables\Filters\Filter;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class EventsTable
|
|
{
|
|
public static $bettype_settings = [];
|
|
|
|
public static $multiline_bookmaker = [];
|
|
|
|
public static $odds_3ways = [];
|
|
|
|
public static $odds_totals = [];
|
|
|
|
public static $odds_totals_q1 = [];
|
|
|
|
public static $odds_dc = [];
|
|
|
|
public static $odds_dnb = [];
|
|
|
|
public static $odds_ggng = [];
|
|
|
|
public static $odds_handicaps = [];
|
|
|
|
public static $odds_handicaps_q1 = [];
|
|
|
|
public static $odds_2ways = [];
|
|
|
|
public static $odds_2ways_s1 = [];
|
|
|
|
public static $odds_tq = [];
|
|
|
|
public static function load_multiline_bookmaker()
|
|
{
|
|
$res = MultilineClient::where('client_id', auth()->user()->client_id)->where('sport_id', auth()->user()->sport_id)->select('bookmaker_id', 'multiline_setting_id')->orderBy('multiline_setting_id')->orderBy('sort')->get();
|
|
|
|
foreach ($res as $value) {
|
|
switch ($value->multiline_setting_id) {
|
|
case 1:
|
|
case 13:
|
|
self::$odds_3ways[] = $value->bookmaker_id;
|
|
break;
|
|
case 2:
|
|
self::$odds_dc[] = $value->bookmaker_id;
|
|
break;
|
|
case 3:
|
|
self::$odds_dnb[] = $value->bookmaker_id;
|
|
break;
|
|
case 4:
|
|
self::$odds_ggng[] = $value->bookmaker_id;
|
|
break;
|
|
case 5:
|
|
self::$odds_tq[] = $value->bookmaker_id;
|
|
break;
|
|
case 8:
|
|
case 14:
|
|
self::$odds_handicaps[] = $value->bookmaker_id;
|
|
break;
|
|
case 9:
|
|
self::$odds_handicaps_q1[] = $value->bookmaker_id;
|
|
break;
|
|
case 7:
|
|
case 12:
|
|
case 16:
|
|
self::$odds_2ways[] = $value->bookmaker_id;
|
|
break;
|
|
case 17:
|
|
self::$odds_2ways_s1[] = $value->bookmaker_id;
|
|
break;
|
|
case 6:
|
|
case 10:
|
|
case 15:
|
|
case 18:
|
|
self::$odds_totals[] = $value->bookmaker_id;
|
|
break;
|
|
case 11:
|
|
self::$odds_totals_q1[] = $value->bookmaker_id;
|
|
break;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
public static function load_bettype_settings()
|
|
{
|
|
self::$bettype_settings = BettypeUser::where('is_active', 1)->pluck('multiline_setting_id')->toArray();
|
|
}
|
|
|
|
public static function configure(Table $table): Table
|
|
{
|
|
self::load_bettype_settings();
|
|
|
|
self::load_multiline_bookmaker();
|
|
|
|
return $table
|
|
->striped()
|
|
->columns([
|
|
IconColumn::make('sport.icon')
|
|
->label('')
|
|
->grow(false)
|
|
->color('primary')
|
|
->width(30)
|
|
->icon(fn ($record) => $record->sport->icon)
|
|
->tooltip(fn ($record) => $record->id)
|
|
->visibleFrom('lg'),
|
|
|
|
MatchIds::make('match_ids')->grow(false)->visibleFrom('xl'),
|
|
|
|
TextColumn::make('starttime')
|
|
->label('Start')
|
|
->alignCenter()
|
|
->dateTime('H:i')
|
|
->weight(FontWeight::Bold)
|
|
->description(fn ($state): string => Carbon::createFromDate($state)->format('d. M')),
|
|
|
|
TextColumn::make('country.name')
|
|
->searchable()
|
|
->wrap()
|
|
->color('gray')
|
|
->label('Event')
|
|
->icon(fn ($record) => $record->country->icon)
|
|
->description(fn ($record) => $record->competition_group->name),
|
|
|
|
TextColumn::make('home.name')
|
|
->wrap()
|
|
->searchable()
|
|
->alignRight(),
|
|
|
|
TextColumn::make('away.name')
|
|
->wrap()
|
|
->searchable(),
|
|
|
|
Column3way::make('odds3way')->bookmakers(self::$odds_3ways)
|
|
->visible(fn () => in_array(1, self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->width(225)
|
|
->label('1 X 2')
|
|
->extraCellAttributes(['class' => 'border-l border-gray-200 dark:border-gray-800']),
|
|
|
|
ColumnDc::make('oddsdc')->bookmakers(self::$odds_dc)
|
|
->visible(fn () => in_array(2, self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->width(225)
|
|
->label('Double Chance')
|
|
->extraCellAttributes(['class' => 'border-l border-gray-200 dark:border-gray-800']),
|
|
|
|
ColumnDnb::make('oddsdnb')->bookmakers(self::$odds_dnb)
|
|
->visible(fn () => in_array(3, self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->width(190)
|
|
->label('Draw No Bet')
|
|
->extraCellAttributes(['class' => 'border-l border-gray-200 dark:border-gray-800']),
|
|
|
|
ColumnGgng::make('oddsggng')->bookmakers(self::$odds_ggng)
|
|
->visible(fn () => in_array(4, self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->width(190)
|
|
->label('Goal No Goal')
|
|
->extraCellAttributes(['class' => 'border-l border-gray-200 dark:border-gray-800']),
|
|
|
|
ColumnTq::make('oddstq')->bookmakers(self::$odds_tq)
|
|
->visible(fn () => in_array(5, self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->width(190)
|
|
->label('To Qualify')
|
|
->extraCellAttributes(['class' => 'border-l border-gray-200 dark:border-gray-800']),
|
|
|
|
ColumnTotal::make('oddstotal')->bookmakers(self::$odds_totals)
|
|
->visible(fn () => in_array(6, self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->width(225)
|
|
->label('Totals')
|
|
->extraCellAttributes(['class' => 'border-l border-gray-200 dark:border-gray-800']),
|
|
])->searchable(['id', 'betsapi_id', 'betradar_id', 'bet365_id', 'bwin_id'])
|
|
->poll('10s')
|
|
->defaultSort('starttime', 'ASC')
|
|
->filters([
|
|
Filter::make('events')
|
|
->schema([
|
|
Select::make('country_id')
|
|
->placeholder('Country')
|
|
->hiddenLabel()
|
|
->label('')
|
|
->searchable()
|
|
->preload()
|
|
->options(function () {
|
|
$res = Event::query()->where('starttime', '>', Carbon::now())->groupBy('country_id')->pluck('country_id')->toArray();
|
|
|
|
return Country::query()->whereIn('tx_id', $res)->pluck('name', 'tx_id');
|
|
})
|
|
->live()
|
|
->reactive()
|
|
->afterStateUpdated(function (callable $set) {
|
|
$set('competition_group_id', null);
|
|
}),
|
|
Select::make('competition_group_id')
|
|
->placeholder('League')
|
|
->hiddenLabel()
|
|
->label('')
|
|
->multiple()
|
|
->columnSpan(2)
|
|
->searchable()
|
|
->options(function (Get $get) {
|
|
if ($get('country_id')) {
|
|
$res = Event::with('country')->with('competition_group')->where('country_id', $get('country_id'))->where('starttime', '>', Carbon::now())->groupBy('competition_group_id')->get();
|
|
} else {
|
|
$res = Event::with('country')->with('competition_group')->where('starttime', '>', Carbon::now())->groupBy('competition_group_id')->get();
|
|
}
|
|
$arr = [];
|
|
foreach ($res as $val) {
|
|
$arr[$val->competition_group_id] = $val->country?->name.' '.$val->competition_group->name;
|
|
}
|
|
asort($arr);
|
|
|
|
return $arr;
|
|
})
|
|
->live(),
|
|
DateRangePicker::make('starttime_period')
|
|
->columnSpan(2)
|
|
->startPrefix('From')
|
|
->displayFormat('d M Y')
|
|
->minDate(now())
|
|
->hiddenLabel()
|
|
->label('')
|
|
->live(),
|
|
Action::make('reset')
|
|
->hiddenLabel()
|
|
->color('gray')
|
|
->icon('heroicon-o-arrow-path')
|
|
->action(function ($livewire) {
|
|
$livewire->resetTableFiltersForm(); // Clears all filters
|
|
$livewire->tableSearch = ''; // Clears the main search bar
|
|
}),
|
|
|
|
])
|
|
->query(function (Builder $query, array $data): Builder {
|
|
return $query
|
|
->when(
|
|
$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)
|
|
)->when(
|
|
$data['starttime_period'],
|
|
function (Builder $query, $starttime_period) {
|
|
if (isset($starttime_period['start']) && isset($starttime_period['end'])) {
|
|
$from = Carbon::createFromDate($starttime_period['start']);
|
|
$end = Carbon::createFromDate($starttime_period['end']);
|
|
|
|
return $query
|
|
->where('starttime', '>=', $from->format('Y-m-d 00:00:00'))
|
|
->where('starttime', '<=', $end->format('Y-m-d 00:00:00'));
|
|
} elseif (isset($starttime_period['start'])) {
|
|
$from = Carbon::createFromDate($starttime_period['start']);
|
|
|
|
return $query
|
|
->where('starttime', '>=', $from->format('Y-m-d 00:00:00'));
|
|
} elseif (isset($starttime_period['end'])) {
|
|
$end = Carbon::createFromDate($starttime_period['end']);
|
|
|
|
return $query
|
|
->where('starttime', '<=', $end->format('Y-m-d 00:00:00'));
|
|
}
|
|
}
|
|
);
|
|
})
|
|
->columns(6)->columnSpan(6),
|
|
], layout: FiltersLayout::AboveContent)
|
|
->filtersFormColumns(6)
|
|
->deferFilters(false)
|
|
->persistFiltersInSession()
|
|
->recordActions([
|
|
ActionGroup::make([
|
|
// EditAction::make(),
|
|
DeleteAction::make()->visible(fn () => auth()->user()->hasRole('super_admin')),
|
|
Action::make('txodds_odds')
|
|
->label('TxOdds')
|
|
->disabled(fn () => ! auth()->user()->hasRole('super_admin'))
|
|
->icon('heroicon-o-arrow-top-right-on-square')
|
|
->url(fn ($record): string => route('txodds_odds', ['sportid' => $record->sport_id, 'txoddsid' => $record->id]))
|
|
->openUrlInNewTab(),
|
|
])->iconButton()
|
|
->icon('heroicon-m-ellipsis-vertical')
|
|
->color('primary'),
|
|
]);
|
|
}
|
|
}
|