49 lines
1.6 KiB
PHP
49 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Models\Booking;
|
|
use App\Models\Event;
|
|
use App\Models\Ride;
|
|
use Filament\Widgets\Widget;
|
|
|
|
class JourneyStoryboard extends Widget
|
|
{
|
|
protected static string $view = 'filament.widgets.journey-storyboard';
|
|
|
|
protected int | string | array $columnSpan = 'full';
|
|
|
|
protected static ?int $sort = 1;
|
|
|
|
protected function getViewData(): array
|
|
{
|
|
$rides = Ride::count();
|
|
$views = Event::where('event_type', 'recommendation_viewed')->count();
|
|
$clicks = Event::where('event_type', 'recommendation_clicked')->count();
|
|
$bookingsCount = Booking::count();
|
|
$latestBooking = Booking::with(['offer', 'ride', 'recommendation'])->latest()->first();
|
|
$commission = (float) Booking::sum('commission_amount');
|
|
$gmv = (float) Booking::sum('amount');
|
|
$rideToBooking = $rides > 0 ? round(($bookingsCount / $rides) * 100, 1) : 0;
|
|
$clickThrough = $views > 0 ? round(($clicks / $views) * 100, 1) : 0;
|
|
$topZone = Ride::query()
|
|
->selectRaw("COALESCE(context_zone, 'General') as zone, COUNT(*) as aggregate")
|
|
->groupBy('zone')
|
|
->orderByDesc('aggregate')
|
|
->value('zone') ?: 'General';
|
|
|
|
return [
|
|
'rides' => $rides,
|
|
'views' => $views,
|
|
'clicks' => $clicks,
|
|
'bookingsCount' => $bookingsCount,
|
|
'latestBooking' => $latestBooking,
|
|
'commission' => $commission,
|
|
'gmv' => $gmv,
|
|
'rideToBooking' => $rideToBooking,
|
|
'clickThrough' => $clickThrough,
|
|
'topZone' => $topZone,
|
|
];
|
|
}
|
|
}
|