schneespur/app/Http/Controllers/Admin/OwntracksOverviewController.php
Michael 2c63440ed8 Revert: move code back to project root from schneespur/ subdirectory
- Reverts the schneespur/ subdirectory restructure (b8e426b)
- Restores package.json and vite.config.js (needed for npm build, were
  removed in an earlier cleanup before the restructure)
- Updates public/build/ assets with current Vite output (new content hashes)
2026-05-17 18:24:26 +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,
]);
}
}