schneespur/release/schneespur-1.0.2/app/Http/Controllers/Admin/OwntracksOverviewController.php
Michael 7288b93500 Release v1.0.2: diagnostic infrastructure core
Add neutral diagnostic framework for future reporting modules:
- DiagnosticReporterInterface, Registry, Manager, PayloadSanitizer
- Laravel exception hook in bootstrap/app.php
- Module permission declarations (requires_permissions in module.json)
- Core diagnostic report points (module boot/install/update failures)
- Module documentation update (moduldoku.md)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-18 16:54:11 +00:00

51 lines
1.6 KiB
PHP

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\GpsPoint;
use App\Models\Job;
use App\Models\User;
use Illuminate\Support\Facades\DB;
use Illuminate\View\View;
class OwntracksOverviewController extends Controller
{
public function __invoke(): View
{
$drivers = User::drivers()->orderBy('name')->get();
$driverIds = $drivers->pluck('id');
$latestGps = collect();
$activeJobs = collect();
if ($driverIds->isNotEmpty()) {
$latestGps = GpsPoint::select('gps_points.*')
->whereIn('gps_points.user_id', $driverIds)
->joinSub(
GpsPoint::select('user_id', DB::raw('MAX(timestamp) as max_ts'))
->whereIn('user_id', $driverIds)
->groupBy('user_id'),
'latest',
fn ($join) => $join->on('gps_points.user_id', '=', 'latest.user_id')
->on('gps_points.timestamp', '=', 'latest.max_ts')
)
->get()
->keyBy('user_id');
$activeJobs = Job::with('customer')
->whereIn('user_id', $driverIds)
->whereNull('ended_at')
->whereHas('workShift', fn ($q) => $q->whereNull('ended_at'))
->get()
->keyBy('user_id');
}
return view('admin.owntracks.overview', [
'drivers' => $drivers,
'latestGps' => $latestGps,
'activeJobs' => $activeJobs,
'now' => now()->timestamp,
]);
}
}