wip del err

This commit is contained in:
salam committed 2026-10-04 15:22:39 +02:00
1 parent 812736ca9a
commit 9bcd4432c6
1210 files changed
-220941

No files matched your search

@@ -1,699 +0,0 @@
<?php
namespace App\Filament\Resources\Events\Tables;
use App\Filament\Resources\Events\Tables\Tools\CompareOptions;
use App\Filament\Resources\Events\Tables\Tools\LoadBettypeSettings;
use App\Filament\Resources\Events\Tables\Tools\LoadCompareDifferences;
use App\Filament\Resources\Events\Tables\Tools\LoadMultiline;
use App\Filament\Tables\Columns\ColumnOdds;
use App\Filament\Tables\Columns\ColumnStarttime;
use App\Filament\Tables\Columns\EventColumn;
use App\Filament\Tables\Columns\MatchIds;
use App\Filament\Tables\Columns\TooltipOdds;
use App\Models\ClientGroupList;
use App\Models\CompetitionGroup;
use App\Models\Country;
use App\Models\Event;
use App\Models\EventBookmaker;
use App\Models\EventUserNote;
use App\Models\EventUserStar;
use App\Models\Group;
use App\Models\OddsTable;
use CodeWithKyrian\FilamentDateRange\Forms\Components\DateRangePicker;
use Filament\Actions\Action;
use Filament\Actions\ActionGroup;
use Filament\Actions\DeleteAction;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Support\Enums\VerticalAlignment;
use Filament\Support\Enums\Width;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Enums\FiltersLayout;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Filters\Indicator;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
class EventsTable
{
public static array $user;
public static array $bettype_settings;
public static array $slots;
public static array $bookmaker;
public static array $filter;
public static function configure(Table $table): Table
{
LoadMultiline::load();
LoadBettypeSettings::load();
return $table
->striped()
->poll('15s')
->deferLoading()
->defaultPaginationPageOption(5)
->extremePaginationLinks()
->paginated([5, 10, 15])
->columns([
IconColumn::make('sport.icon')
->label('')
->icon(fn($record) => $record->sport->icon)
->tooltip(fn($record) => $record->id)
->visibleFrom('lg'),
MatchIds::make('ids')->grow(false)->visibleFrom('xl')
->visible(fn() => auth()->user()->hasRole('super_admin')),
ColumnStarttime::make('start'),
TextColumn::make('country.name')
->label('League')
->wrap()
->hidden(fn() => auth()->user()->sport_id == 5)
->color('gray')
->icon(fn($record) => $record->country?->icon)
->description(fn($record) => ucwords($record->group?->name)),
EventColumn::make('event'),
TooltipOdds::make('ml')->bettype('odds_2ways')->label('')->visible(fn() => in_array('odds_2ways', self::$bettype_settings)),
ColumnOdds::make('odds_2ways')->bettype('odds_2ways')
->visible(fn() => in_array('odds_2ways', self::$bettype_settings))
->verticalAlignment(VerticalAlignment::Start)
->label('ML'),
TooltipOdds::make('mls1')->bettype('odds_2ways_s1')->label('')->visible(fn() => in_array('odds_2ways_s1', self::$bettype_settings)),
ColumnOdds::make('odds_2ways_s1')->bettype('odds_2ways_s1')
->visible(fn() => in_array('odds_2ways_s1', self::$bettype_settings))
->verticalAlignment(VerticalAlignment::Start)
->label('ML S1'),
TooltipOdds::make('1x2')->bettype('odds_3ways')->label('')->visible(fn() => in_array('odds_3ways', self::$bettype_settings)),
ColumnOdds::make('odds_3ways')
->bettype('odds_3ways')
->visible(fn() => in_array('odds_3ways', self::$bettype_settings))
->verticalAlignment(VerticalAlignment::Start)
->label('1X2'),
TooltipOdds::make('1x2ht')->bettype('odds_3ways_ht')->label('')->visible(fn() => in_array('odds_3ways_ht', self::$bettype_settings)),
ColumnOdds::make('odds_3ways_ht')->bettype('odds_3ways_ht')
->visible(fn() => in_array('odds_3ways_ht', self::$bettype_settings))
->verticalAlignment(VerticalAlignment::Start)
->label('1X2 HT'),
TooltipOdds::make('total')->bettype('odds_totals')->label('')->visible(fn() => in_array('odds_totals', self::$bettype_settings)),
ColumnOdds::make('odds_totals')->bettype('odds_totals')
->visible(fn() => in_array('odds_totals', self::$bettype_settings))
->verticalAlignment(VerticalAlignment::Start)
->label('Totals'),
TooltipOdds::make('total_ht')->bettype('odds_totals_ht')->label('')->visible(fn() => in_array('odds_totals_ht', self::$bettype_settings)),
ColumnOdds::make('odds_totals_ht')->bettype('odds_totals_ht')
->visible(fn() => in_array('odds_totals_ht', self::$bettype_settings))
->verticalAlignment(VerticalAlignment::Start)
->label('Totals HT'),
TooltipOdds::make('total_q1')->bettype('odds_totals_q1')->label('')->visible(fn() => in_array('odds_totals_q1', self::$bettype_settings)),
ColumnOdds::make('odds_totals_q1')->bettype('odds_totals_q1')
->visible(fn() => in_array('odds_totals_q1', self::$bettype_settings))
->verticalAlignment(VerticalAlignment::Start)
->alignCenter()
->label('Totals Q1'),
TooltipOdds::make('points')->bettype('odds_points')->label('')->visible(fn() => in_array('odds_points', self::$bettype_settings)),
ColumnOdds::make('odds_points')->bettype('odds_points')
->visible(fn() => in_array('odds_points', self::$bettype_settings))
->verticalAlignment(VerticalAlignment::Start)
->label('Points'),
TooltipOdds::make('points_ht')->bettype('odds_points_ht')->label('')->visible(fn() => in_array('odds_points_ht', self::$bettype_settings)),
ColumnOdds::make('odds_points_ht')->bettype('odds_points_ht')
->visible(fn() => in_array('odds_points_ht', self::$bettype_settings))
->verticalAlignment(VerticalAlignment::Start)
->label('Points HT'),
TooltipOdds::make('points_q1')->bettype('odds_points_q1')->label('')->visible(fn() => in_array('odds_points_q1', self::$bettype_settings)),
ColumnOdds::make('odds_points_q1')->bettype('odds_points_q1')
->visible(fn() => in_array('odds_points_q1', self::$bettype_settings))
->verticalAlignment(VerticalAlignment::Start)
->label('Points Q1'),
TooltipOdds::make('ggng')->bettype('odds_ggng')->label('')->visible(fn() => in_array('odds_ggng', self::$bettype_settings)),
ColumnOdds::make('odds_ggng')->bettype('odds_ggng')
->visible(fn() => \in_array('odds_ggng', self::$bettype_settings))
->verticalAlignment(VerticalAlignment::Start)
->label('Goal No Goal'),
TooltipOdds::make('dc')->bettype('odds_dc')->label('')->visible(fn() => in_array('odds_dc', self::$bettype_settings)),
ColumnOdds::make('odds_dc')->bettype('odds_dc')
->visible(fn() => \in_array('odds_dc', self::$bettype_settings))
->verticalAlignment(VerticalAlignment::Start)
->label('Double Chance'),
TooltipOdds::make('tq')->bettype('odds_tq')->label('')->visible(fn() => in_array('odds_tq', self::$bettype_settings)),
ColumnOdds::make('odds_tq')->bettype('odds_tq')
->visible(fn() => \in_array('odds_tq', self::$bettype_settings))
->verticalAlignment(VerticalAlignment::Start)
->label('To Qualify'),
TooltipOdds::make('dnb')->bettype('odds_dnb')->label('')->visible(fn() => in_array('odds_dnb', self::$bettype_settings)),
ColumnOdds::make('odds_dnb')->bettype('odds_dnb')
->visible(fn() => \in_array('odds_dnb', self::$bettype_settings))
->verticalAlignment(VerticalAlignment::Start)
->label('Draw No Bet'),
])
->searchable(['id', 'home.name', 'away.name', 'betsapi_id', 'betradar_id', 'bet365_id', 'bwin_id', 'event_bookmaker.event_id'])
->extremePaginationLinks()
->filters([
Filter::make('events')
->columns(7)->columnSpan(7)
->schema([
Hidden::make('filter_alarm_green'),
Hidden::make('filter_alarm_yellow'),
Hidden::make('filter_alarm_red'),
Hidden::make('filter_stars'),
Hidden::make('filter_notes'),
Hidden::make('filter_periode'),
Select::make('country_id')
->placeholder('Country')
->prefixIcon('phosphor-flag')
->hiddenLabel()
->label('')
->multiple()
->searchable()
->preload()
->options(function () {
$res = Event::where('has_markets', 1)
->where('sport_id', auth()->user()->sport_id)
->where('starttime', '>=', Carbon::now())
->groupBy('country_id')
->pluck('country_id')->toArray();
return Country::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id');
})
->live()
->reactive()
->afterStateUpdated(function (callable $set) {
$set('competition_group_id', null);
}),
Select::make('client_group_list_id')
->placeholder('Custom Groups')
->prefixIcon('phosphor-user-list')
->searchable()
->hiddenLabel()
->label('')
->preload()
->options(fn() => ClientGroupList::where('sport_id', auth()->user()->sport_id)
->where('client_id', auth()->user()->client_id)
->pluck('name', 'id'))
->live(),
Select::make('competition_group_id')
->placeholder('League')
->prefixIcon('phosphor-trophy')
->hiddenLabel()
->label('')
->multiple()
->searchable()
->options(function (Get $get) {
if ($get('client_group_list_id')) {
$list = ClientGroupList::where('id', $get('client_group_list_id'))->value('client_groups');
$res = Event::where('has_markets', 1)
->with('country')
->with('competition_group')
->where('sport_id', auth()->user()->sport_id)
->where('starttime', '>', Carbon::now())
->whereIn('competition_group_id', $list)
->get();
} elseif ($get('country_id')) {
$res = Event::where('has_markets', 1)
->with('country')
->with('competition_group')
->where('sport_id', auth()->user()->sport_id)
->where('starttime', '>', Carbon::now())
->whereIn('country_id', $get('country_id'))
->get();
} else {
$res = Event::where('has_markets', 1)
->with('country')
->with('competition_group')
->where('sport_id', auth()->user()->sport_id)
->where('starttime', '>', Carbon::now())
->get();
}
$arr = [];
foreach ($res as $val) {
$arr[$val->competition_group_id] = $val->country?->name . ' ' . $val->competition_group?->name;
}
asort($arr);
return $arr;
})
->live(),
Select::make('competition_group_id')
->visible(fn() => auth()->user()->sport_id == 5)
->placeholder('Tournament')
->prefixIcon('phosphor-trophy')
->columnSpan(2)
->hiddenLabel()
->label('')
->multiple()
->searchable()
->options(function () {
$res = Event::where('has_markets', 1)
->with('competition_group')
->where('sport_id', auth()->user()->sport_id)
->where('starttime', '>', Carbon::now())
// ->groupBy('competition_group_id')
->get();
$arr = [];
foreach ($res as $val) {
if (! isset($arr[$val->competition_group_id])) {
$arr[$val->competition_group_id] = $val->competition_group->name;
}
}
asort($arr);
return $arr;
})
->live(),
DateRangePicker::make('starttime_period')
->columnSpan(2)
->displayFormat('d M Y')
->minDate(now())
->hiddenLabel()
->label('')
->live(),
TextInput::make('favorit_threshold')
->prefixIcon('phosphor-less-than')
->hintIconTooltip('Filter Favorit')
->suffix('Favorit')
->numeric()
->minValue(1.01)
->maxValue(3.00)
->step(0.01)
->hiddenLabel()
->live(),
Select::make('filter_compare_differences')
->placeholder('Compare')
->prefixIcon('phosphor-funnel')
->hiddenLabel()
->allowHtml()
->options(fn() => CompareOptions::load()),
])
->query(function (Builder $query, array $data): Builder {
return $query->when(
$data['country_id'],
function (Builder $query, $country_id) {
$query->whereIn('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['client_group_list_id'],
function (Builder $query, $client_group_list_id) {
$client_group_list_ids = ClientGroupList::where('id', $client_group_list_id)->value('client_groups');
$query->whereIn('competition_group_id', $client_group_list_ids);
}
)->when(
$data['starttime_period'],
function (Builder $query, $starttime_period) {
// dd($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)
->where('starttime', '<=', $end);
} elseif (isset($starttime_period['start'])) {
$from = Carbon::createFromDate($starttime_period['start']);
return $query
->where('starttime', '>=', $from);
} elseif (isset($starttime_period['end'])) {
$end = Carbon::createFromDate($starttime_period['end']);
return $query
->where('starttime', '<=', $end);
}
}
)->when(
$data['filter_alarm_green'],
function (Builder $query, $filter_alarm_green) {
$res = OddsTable::where('name', $filter_alarm_green)->value('fieldnames');
$fieldnames = explode(',', $res);
return $query->whereHas('event_bookmaker', function ($query) use ($fieldnames) {
$query->where('bookmaker_id', auth()->user()->bookmaker_id)
->where(function ($query) use ($fieldnames) {
foreach ($fieldnames as $field) {
$query->orWhere($field, 1);
}
});
});
}
)->when(
$data['filter_alarm_yellow'],
function (Builder $query, $filter_alarm_yellow) {
$res = OddsTable::where('name', $filter_alarm_yellow)->value('fieldnames');
$fieldnames = explode(',', $res);
return $query->whereHas('event_bookmaker', function ($query) use ($fieldnames) {
$query->where('bookmaker_id', auth()->user()->bookmaker_id)
->where(function ($query) use ($fieldnames) {
foreach ($fieldnames as $field) {
$query->orWhere($field, 2);
}
});
});
}
)->when(
$data['filter_alarm_red'],
function (Builder $query, $filter_alarm_red) {
$res = OddsTable::where('name', $filter_alarm_red)->value('fieldnames');
$fieldnames = explode(',', $res);
return $query->whereHas('event_bookmaker', function ($query) use ($fieldnames) {
$query->where('bookmaker_id', auth()->user()->bookmaker_id)
->where(function ($query) use ($fieldnames) {
foreach ($fieldnames as $field) {
$query->orWhere($field, 3);
}
});
});
}
)->when(
$data['filter_compare_differences'],
function (Builder $query, $filter_compare_differences) {
$opt = explode('-', $filter_compare_differences);
$compare_bookmaker_id = (int) $opt[2];
switch (auth()->user()->sport_id) {
case 1:
case 2:
$event_ids = LoadCompareDifferences::load($opt[0], $opt[1], 'odds_3ways', $compare_bookmaker_id);
break;
case 3:
$event_ids = LoadCompareDifferences::load($opt[0], $opt[1], 'odds_points', $compare_bookmaker_id);
break;
case 5:
$event_ids = LoadCompareDifferences::load($opt[0], $opt[1], 'odds_2ways', $compare_bookmaker_id);
break;
}
$query->whereIn('id', $event_ids);
}
)->when(
$data['filter_stars'],
function (Builder $query, $filter_stars) {
$query->whereHas('event_user_star');
}
)->when(
in_array('odds_tq', self::$bettype_settings),
function (Builder $query, $filter_stars) {
$query->whereHas('odds_tq');
}
)->when(
$data['filter_notes'],
function (Builder $query, $filter_notes) {
$query->whereHas('event_user_note');
}
)->when(
$data['favorit_threshold'],
function (Builder $query, $favorit_threshold) {
switch (auth()->user()->sport_id) {
case 1:
return $query->whereHas('odds_3ways', function ($query) use ($favorit_threshold) {
$query->where('bookmaker_id', auth()->user()->bookmaker_id)->whereRaw('LEAST(h3w, d3w, a3w) BETWEEN ? AND ?', [1, $favorit_threshold]);
});
break;
case 2:
return $query->whereHas('odds_3ways', function ($query) use ($favorit_threshold) {
$query->where('bookmaker_id', auth()->user()->bookmaker_id)->whereRaw('LEAST(h3w, d3w, a3w) BETWEEN ? AND ?', [1, $favorit_threshold]);
});
break;
case 3:
return $query->whereHas('odds_points', function ($query) use ($favorit_threshold) {
$query->where('bookmaker_id', auth()->user()->bookmaker_id)->where('active_spread', 1)->whereRaw('LEAST(home, away) BETWEEN ? AND ?', [1, $favorit_threshold]);
});
break;
case 5:
return $query->whereHas('odds_2ways', function ($query) use ($favorit_threshold) {
$query->where('bookmaker_id', auth()->user()->bookmaker_id)->whereRaw('LEAST(h2w, a2w) BETWEEN ? AND ?', [1, $favorit_threshold]);
});
break;
}
}
);
})->indicateUsing(function (array $data): array {
$indicators = [];
if ($data['country_id'] ?? null) {
$countries = Country::whereIn('id', $data['country_id'])->pluck('name')->toArray();
if (count($countries) > 1) {
$indicators[] = Indicator::make(implode(', ', $countries))->removeField('country_id')->color('info');
} else {
$indicators[] = Indicator::make($countries[0])->removeField('country_id')->color('info');
}
}
if ($data['group_id'] ?? null) {
$group_ids = Group::whereIn('id', $data['group_id'])->pluck('name')->toArray();
if (count($group_ids) > 1) {
$indicators[] = Indicator::make(implode(', ', $group_ids))->removeField('group_id')->color('info');
} else {
$indicators[] = Indicator::make($group_ids[0])->removeField('group_id')->color('info');
}
}
if ($data['client_group_list_id'] ?? null) {
$client_group_list_name = ClientGroupList::where('id', $data['client_group_list_id'])->value('name');
$indicators[] = Indicator::make('Custom Group: ' . $client_group_list_name)->removeField('client_group_list_id')->color('info');
}
if ($data['filter_stars'] ?? null) {
$indicators[] = Indicator::make('Favorits')->removeField('filter_stars')->color('info');
}
if (in_array('odds_tq', self::$bettype_settings)) {
$indicators[] = Indicator::make('To Qualify')->color('info')->removable(false);
}
if ($data['filter_notes'] ?? null) {
$indicators[] = Indicator::make('Notes')->removeField('filter_notes')->color('info');
}
if ($data['filter_alarm_green'] ?? null) {
$title = OddsTable::where('name', $data['filter_alarm_green'])->value('title');
$indicators[] = Indicator::make('Alarms: ' . $title)->removeField('filter_alarm_green')->color('success');
}
if ($data['filter_alarm_yellow'] ?? null) {
$title = OddsTable::where('name', $data['filter_alarm_yellow'])->value('title');
$indicators[] = Indicator::make('Alarms: ' . $title)->removeField('filter_alarm_yellow')->color('info');
}
if ($data['filter_alarm_red'] ?? null) {
$title = OddsTable::where('name', $data['filter_alarm_red'])->value('title');
$indicators[] = Indicator::make('Alarms: ' . $title)->removeField('filter_alarm_red')->color('danger');
}
if ($data['starttime_period'] ?? null) {
$span = $data['starttime_period'];
$text = '';
if ($span['start'] ?? null) {
$text .= Carbon::parse($span['start'])->format('d. M.');
}
if ($span['end'] ?? null) {
$text .= ' - ' . Carbon::parse($span['end'])->format('d. M.');
}
if ($text) {
$indicators[] = Indicator::make($text)->removeField('starttime_period.start')->color('info');
}
}
if ($data['competition_group_id'] ?? null) {
$competition_groups = CompetitionGroup::whereIn('id', $data['competition_group_id'])->pluck('name')->toArray();
if (count($competition_groups) > 1) {
$indicators[] = Indicator::make(implode(', ', $competition_groups))->removeField('competition_group_id')->color('info');
} else {
$indicators[] = Indicator::make($competition_groups[0])->removeField('competition_group_id')->color('info')->color('info');
}
}
if ($data['favorit_threshold'] ?? null) {
switch (auth()->user()->sport_id) {
case 1:
$indicators[] = Indicator::make('1X2 Fav <= ' . $data['favorit_threshold'])->removeField('favorit_threshold')->color('warning');
break;
case 2:
$indicators[] = Indicator::make('1X2 Fav <= ' . $data['favorit_threshold'])->removeField('favorit_threshold')->color('warning');
break;
case 3:
$indicators[] = Indicator::make('HC Fav <= ' . $data['favorit_threshold'])->removeField('favorit_threshold')->color('warning');
break;
case 5:
$indicators[] = Indicator::make('ML Fav <= ' . $data['favorit_threshold'])->removeField('favorit_threshold')->color('warning');
break;
}
}
if ($data['filter_compare_differences'] ?? null) {
$opt = explode('-', $data['filter_compare_differences']);
$title = $opt[0];
switch ($opt[1]) {
case 'lte':
$title .= ' ≤ ';
break;
case 'gte':
$title .= ' ≥ ';
break;
case 'lt':
$title .= ' > ';
break;
}
$title .= $opt[3];
$indicators[] = Indicator::make($title)->removeField('filter_compare_differences')->color('warning');
}
return $indicators;
}),
], layout: FiltersLayout::AboveContent)
->deferFilters(false)
->hiddenFilterIndicators(false)
->persistFiltersInSession()
->emptyStateHeading('No events')
->emptyStateDescription('Modify the filter')
->recordUrl(null) // disable row click for page
->recordAction(null) // disable row click for modal
->recordActions([
// Action::make('event-statistic')
// ->iconButton()
// ->modalIcon('phosphor-chart-line')
// ->color('gray')
// ->modalHeading(fn ($record) => $record->country->name.' - '.$record->group->name)
// ->icon('phosphor-chart-line')
// ->modalContent(fn ($record): View => view(
// 'statistic-event-chart',
// ['record' => $record],
// )),
Action::make('star')
->iconButton()
->color(function ($record) {
if (isset($record->event_user_star->id)) {
return 'info';
} else {
return 'gray';
}
})
->icon(function ($record) {
if (isset($record->event_user_star->id)) {
return 'phosphor-star-fill';
} else {
return 'phosphor-star-duotone';
}
})
->tooltip('Add to favorits')
->action(function ($record) {
$res = EventUserStar::where('event_id', $record->id)
->where('user_id', auth()->user()->id)
->first();
if ($res) {
EventUserStar::find($res->id)->delete();
} else {
EventUserStar::insert(['event_id' => $record->id, 'user_id' => auth()->user()->id]);
}
}),
Action::make('event_note')
->modalIcon('phosphor-note-pencil-duotone')
->modalWidth(Width::Large)
->modalSubmitActionLabel('Save')
->extraModalFooterActions(fn(Action $action, $record) => $record->event_user_note->isEmpty() ? [] : [$action->makeModalSubmitAction('Delete', arguments: ['delete' => true])->color('danger')])
->fillForm(data: function ($record) {
foreach ($record->event_user_note as $value) {
if ($value->user_id == auth()->user()->id && $value->bookmaker_id == auth()->user()->bookmaker_id) {
return [
'event_user_note_id' => $value->id,
'message' => $value->message,
];
}
}
return ['event_user_note_id' => ''];
})
->schema([
Hidden::make('event_user_note_id'),
Textarea::make('message')
->rows(2)
->hiddenLabel(),
])
->icon('phosphor-note-pencil-duotone')
->iconButton()
->tooltip(fn($record) => view('filament.resources.events.tooltip.event-user-note-tooltip', ['notes' => $record->event_user_note]))
->action(function ($record, array $data, $arguments = []) {
if ($arguments) {
EventUserNote::where('id', $data['event_user_note_id'])->delete();
} elseif ($data['event_user_note_id']) {
if (! $data['message']) {
EventUserNote::where('id', $data['event_user_note_id'])->delete();
} else {
EventUserNote::where('id', $data['event_user_note_id'])->update(['message' => $data['message']]);
}
} else {
EventUserNote::updateOrCreate([
'event_id' => $record->id,
'user_id' => auth()->user()->id,
'client_id' => auth()->user()->client_id,
'bookmaker_id' => auth()->user()->bookmaker_id,
], [
'message' => $data['message'],
]);
}
})
->color(fn($record) => $record->event_user_note->isEmpty() ? 'gray' : 'info'),
ActionGroup::make([
DeleteAction::make()->visible(fn() => auth()->user()->hasRole('super_admin')),
Action::make('txodds_odds')
->label('TxOdds')
->disabled(fn() => ! auth()->user()->hasRole('super_admin'))
->icon('phosphor-arrow-square-out')
->url(fn($record): string => route('txodds_odds', ['sportid' => $record->sport_id, 'txoddsid' => $record->id]))
->openUrlInNewTab(),
Action::make('swap_elements')
->icon('phosphor-swap')
->action(function ($record, $livewire) {
EventBookmaker::where('event_id', $record->id)->where('bookmaker_id', auth()->user()->bookmaker_id)->update(['is_swopped' => DB::raw('!is_swopped')]);
$livewire->dispatch('refreshBettypeMenu');
}),
])->iconButton()
->icon('phosphor-dots-three-vertical'),
]);
}
}
@@ -1,73 +0,0 @@
<?php
namespace App\Filament\Resources\Events\Tables\Tools;
use App\Filament\Resources\Events\Tables\EventsTable;
use App\Models\Bookmaker;
class CompareOptions
{
public static function load()
{
$map = Bookmaker::map();
$favorits = [];
$margins = [];
$x = [];
switch (auth()->user()->sport_id) {
case 1:
case 2:
$table = 'odds_3ways';
break;
case 3:
$table = 'odds_points';
break;
case 5:
$table = 'odds_2ways';
break;
}
$options = [];
foreach (EventsTable::$slots[$table] as $bookmaker_id) {
if (isset($map[$bookmaker_id])) {
$option = 'Favorit-lte-'.$bookmaker_id.'-'.$map[$bookmaker_id]['name'];
$favorits[$option] = 'Favorit ≤ '.$map[$bookmaker_id]['name'];
}
}
foreach (EventsTable::$slots[$table] as $bookmaker_id) {
if (isset($map[$bookmaker_id])) {
$option = 'Favorit-gte-'.$bookmaker_id.'-'.$map[$bookmaker_id]['name'];
$favorits[$option] = 'Favorit ≥ '.$map[$bookmaker_id]['name'];
}
}
$options['Favorits'] = $favorits;
foreach (EventsTable::$slots[$table] as $bookmaker_id) {
if (isset($map[$bookmaker_id])) {
$option = 'Margin-gte-'.$bookmaker_id.'-'.$map[$bookmaker_id]['name'];
$margins[$option] = 'Margin ≥ '.$map[$bookmaker_id]['name'];
}
}
foreach (EventsTable::$slots[$table] as $bookmaker_id) {
if (isset($map[$bookmaker_id])) {
$option = 'Margin-lt-'.$bookmaker_id.'-'.$map[$bookmaker_id]['name'];
$margins[$option] = 'Margin < '.$map[$bookmaker_id]['name'];
}
}
$options['Margins'] = $margins;
if (auth()->user()->sport_id == 1) {
foreach (EventsTable::$slots[$table] as $bookmaker_id) {
if (isset($map[$bookmaker_id])) {
$option = 'X-lt-'.$bookmaker_id.'-'.$map[$bookmaker_id]['name'];
$x[$option] = 'X < '.$map[$bookmaker_id]['name'];
}
}
$options['X'] = $x;
}
return $options;
}
}
@@ -1,25 +0,0 @@
<?php
namespace App\Filament\Resources\Events\Tables\Tools;
use App\Filament\Resources\Events\Tables\EventsTable;
use App\Models\BettypeUser;
class LoadBettypeSettings
{
public static function load()
{
$res = BettypeUser::with('multiline_setting')
->where('user_id', auth()->user()->id)
->where('sport_id', auth()->user()->sport_id)
->where('is_active', 1)
->orderBy('sorting')
->get();
$arr = [];
foreach ($res as $value) {
$arr[] = $value->multiline_setting->table;
}
EventsTable::$bettype_settings = $arr;
}
}
@@ -1,30 +0,0 @@
<?php
namespace App\Filament\Resources\Events\Tables\Tools;
use App\Models\Event;
use Illuminate\Support\Carbon;
class LoadClientStartimeDifference
{
public static function load()
{
$events = Event::with('event_bookmaker')
->where('sport_id', auth()->user()->sport_id)
->where('starttime', '>=', Carbon::now())
->whereHas('event_bookmaker', function ($query) {
$query->where('bookmaker_id', auth()->user()->bookmaker_id);
})
->get();
$event_ids = [];
foreach ($events as $event) {
if ($event->starttime != $event->event_bookmaker->starttime) {
$event_ids[] = $event->id;
}
}
return array_unique($event_ids);
}
}
@@ -1,107 +0,0 @@
<?php
namespace App\Filament\Resources\Events\Tables\Tools;
use App\Models\OddsTable;
use Illuminate\Support\Facades\DB;
class LoadCompareDifferences
{
public static function load($target, $mode, $table, $compare_bookmaker_id)
{
$fields = OddsTable::fields();
// dd($target, $mode, $table, $compare_bookmaker_id);
// echo $table."\n";
// dd(auth()->user()->sport_id);
$has_active_spread = OddsTable::where('name', $table)->value('has_active_spread');
if ($has_active_spread) {
$clients = DB::table($table)
->where('bookmaker_id', auth()->user()->bookmaker_id)
->where('active_spread', 1)
->get();
$comparing = DB::table($table)
->where('bookmaker_id', $compare_bookmaker_id)
->where('active_spread', 1)
->get();
} else {
// $clients = DB::table($table)->whereIn('bookmaker_id', [auth()->user()->bookmaker_id, $compare_bookmaker_id])->get();
$clients = DB::table($table)
->where('bookmaker_id', auth()->user()->bookmaker_id)
->get();
$comparing = DB::table($table)
->where('bookmaker_id', $compare_bookmaker_id)
->get();
}
$event_ids = [];
foreach ($clients as $client) {
$row1 = get_object_vars($client);
foreach ($comparing as $compare) {
$row2 = get_object_vars($compare);
if ($row1['event_id'] == $row2['event_id']) {
switch ($target) {
case 'Favorit':
$bk = 100;
$co = 100;
foreach ($fields[$table] as $field) {
if ($row1[$field] < $bk) {
$bk = $row1[$field];
}
if ($row2[$field] < $co) {
$co = $row2[$field];
}
}
switch ($mode) {
case 'lte':
if ($bk > 1 && $co > 1 && $bk <= $co) {
$event_ids[] = $row1['event_id'];
}
break;
case 'gte':
if ($bk > 1 && $co > 1 && $bk >= $co) {
$event_ids[] = $row1['event_id'];
}
break;
}
break;
case 'Margin':
switch ($mode) {
case 'gte':
if ($row1['margin'] >= $row2['margin']) {
$event_ids[] = $row1['event_id'];
}
break;
case 'lt':
if ($row1['margin'] < $row2['margin']) {
$event_ids[] = $row1['event_id'];
}
break;
}
break;
case 'X':
if ($row1['d3w'] < $row2['d3w']) {
$event_ids[] = $row1['event_id'];
}
break;
}
}
}
}
return array_unique($event_ids);
}
}
@@ -1,51 +0,0 @@
<?php
namespace App\Filament\Resources\Events\Tables\Tools;
use App\Filament\Resources\Events\Tables\EventsTable;
use App\Models\ComparingBookmaker;
use App\Models\MultilineClient;
use App\Models\MultilineSetting;
class LoadMultiline
{
public static function load()
{
$cb = ComparingBookmaker::where('sport_id', auth()->user()->sport_id)
->where('client_bookmaker_id', auth()->user()->bookmaker_id)
->orderBy('sorting', 'desc')
->select('bookmaker_id', 'time_lastcheck', 'margin_threshold', 'is_active')
->get();
$bookmakers = [];
$filter = [];
foreach ($cb as $value) {
if (auth()->user()->bookmaker_id != $value->bookmaker_id) {
$bookmakers[] = $value->bookmaker_id;
$filter[$value->bookmaker_id] = [
'time_lastcheck' => $value->time_lastcheck,
'margin' => $value->margin_threshold,
];
}
}
$res = MultilineSetting::where('sport_id', auth()->user()->sport_id)->get();
foreach ($res as $value) {
EventsTable::$filter[$value->table] = $filter;
EventsTable::$bookmaker[$value->table] = $bookmakers;
}
$res = MultilineClient::with('multiline_setting')
->where('sport_id', auth()->user()->sport_id)
->where('client_bookmaker_id', auth()->user()->bookmaker_id)
->select('bookmaker_id', 'multiline_setting_id')
->orderBy('sort')
->get();
foreach ($res as $value) {
$table = $value->multiline_setting->table;
EventsTable::$slots[$table][] = (int) $value->bookmaker_id;
}
}
}
@@ -1,47 +0,0 @@
<?php
namespace App\Filament\Resources\Events\Tables\Tools;
use App\Filament\Resources\Events\Tables\EventsTable;
use App\Models\OddsTable;
use Illuminate\Support\Facades\DB;
class LoadPartnerDifferences
{
public static function load()
{
$event_ids = [];
foreach (EventsTable::$bettype_settings as $table) {
$has_active_spread = OddsTable::where('name', $table)->value('has_active_spread');
if ($has_active_spread) {
$events = DB::table($table)
->whereIn('bookmaker_id', [auth()->user()->bookmaker_id, auth()->user()->partner_bookmaker_id])
->where('active_spread', 1)
->get();
} else {
$events = DB::table($table)
->whereIn('bookmaker_id', [auth()->user()->bookmaker_id, auth()->user()->partner_bookmaker_id])
->get();
}
$res = [];
foreach ($events as $value) {
$value = get_object_vars($value);
$event_id = $value['event_id'];
foreach (['id', 'event_id', 'sport_id', 'bookmaker_id', 'provider_id', 'offer_id', 'bmoid', 'margin', 'flags', 'nuh_check', 'last_updated', 'created_at', 'updated_at'] as $fieldname) {
unset($value[$fieldname]);
}
$res[$event_id][] = $value;
}
foreach ($res as $event_id => $odds) {
if (count($odds) == 2 && array_diff($odds[0], $odds[1])) {
$event_ids[] = $event_id;
}
}
}
return array_unique($event_ids);
}
}