feat: add ActivityLogController, application layout, activity log view, and route definitions
This commit is contained in:
@@ -61,4 +61,91 @@ class ActivityLogController extends Controller
|
||||
|
||||
return view('qma.activity_log', compact('activities', 'gates'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tampilkan Summary Aktivitas Kendaraan (Rekapitulasi Armada, Driver, Pos Gerbang & Statistik).
|
||||
*/
|
||||
public function summary(Request $request): View
|
||||
{
|
||||
$startDate = $request->input('start_date');
|
||||
$endDate = $request->input('end_date');
|
||||
$type = $request->input('type');
|
||||
$gateId = $request->input('gate_id');
|
||||
|
||||
$query = VehicleActivity::query();
|
||||
|
||||
if ($request->filled('start_date') && $request->filled('end_date')) {
|
||||
$start = Carbon::parse($startDate)->startOfDay();
|
||||
$end = Carbon::parse($endDate)->endOfDay();
|
||||
$query->whereBetween('recorded_at', [$start, $end]);
|
||||
}
|
||||
|
||||
if ($request->filled('gate_id')) {
|
||||
$query->where('gate_id', $gateId);
|
||||
}
|
||||
|
||||
if ($request->filled('type')) {
|
||||
$type = $request->input('type');
|
||||
$query->whereHas('vehicle', function ($q) use ($type) {
|
||||
if ($type === 'lv' || $type === 'light_vehicle') {
|
||||
$q->where('category', 'light_vehicle');
|
||||
} elseif ($type === 'support' || $type === 'unit_support') {
|
||||
$q->where('category', 'unit_support');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$totalActivities = (clone $query)->count();
|
||||
$totalDistance = (clone $query)->sum('distance');
|
||||
$inCount = (clone $query)->where('direction', 'in')->count();
|
||||
$outCount = (clone $query)->where('direction', 'out')->count();
|
||||
$approvedCount = (clone $query)->where('validation_status', 'approved')->count();
|
||||
$pendingCount = (clone $query)->where('validation_status', 'pending')->count();
|
||||
$rejectedCount = (clone $query)->where('validation_status', 'rejected')->count();
|
||||
|
||||
// Rekapitulasi per Kendaraan
|
||||
$vehicleSummaries = (clone $query)
|
||||
->selectRaw("vehicle_id, COUNT(*) as total_trips, SUM(CASE WHEN direction = 'in' THEN 1 ELSE 0 END) as in_trips, SUM(CASE WHEN direction = 'out' THEN 1 ELSE 0 END) as out_trips, SUM(distance) as total_km")
|
||||
->groupBy('vehicle_id')
|
||||
->with('vehicle')
|
||||
->orderByDesc('total_km')
|
||||
->get();
|
||||
|
||||
$activeVehiclesCount = $vehicleSummaries->count();
|
||||
$avgDistancePerTrip = $totalActivities > 0 ? round($totalDistance / $totalActivities, 1) : 0;
|
||||
|
||||
// Rekapitulasi per Driver (Top Driver)
|
||||
$driverSummaries = (clone $query)
|
||||
->selectRaw("driver_id, COUNT(*) as total_trips, SUM(distance) as total_km")
|
||||
->groupBy('driver_id')
|
||||
->with('driver')
|
||||
->orderByDesc('total_km')
|
||||
->take(10)
|
||||
->get();
|
||||
|
||||
// Rekapitulasi per Pos Gerbang
|
||||
$gateSummaries = (clone $query)
|
||||
->selectRaw("gate_id, COUNT(*) as total_trips, SUM(CASE WHEN direction = 'in' THEN 1 ELSE 0 END) as in_trips, SUM(CASE WHEN direction = 'out' THEN 1 ELSE 0 END) as out_trips")
|
||||
->groupBy('gate_id')
|
||||
->with('gate')
|
||||
->get();
|
||||
|
||||
$gates = Gate::where('is_active', true)->orderBy('name')->get();
|
||||
|
||||
return view('qma.activity_summary', compact(
|
||||
'totalActivities',
|
||||
'totalDistance',
|
||||
'activeVehiclesCount',
|
||||
'avgDistancePerTrip',
|
||||
'inCount',
|
||||
'outCount',
|
||||
'approvedCount',
|
||||
'pendingCount',
|
||||
'rejectedCount',
|
||||
'vehicleSummaries',
|
||||
'driverSummaries',
|
||||
'gateSummaries',
|
||||
'gates'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,6 +169,12 @@
|
||||
<i class="fa-solid fa-clipboard-list text-base w-5 text-center"></i>
|
||||
<span>Log Aktivitas Kendaraan</span>
|
||||
</a>
|
||||
|
||||
<a href="{{ route('qma.activity.summary') }}"
|
||||
class="flex items-center space-x-3 px-3.5 py-2.5 text-sm {{ request()->routeIs('qma.activity.summary') ? 'sidebar-item-active' : 'sidebar-item-inactive' }}">
|
||||
<i class="fa-solid fa-chart-pie text-base w-5 text-center"></i>
|
||||
<span>Summary Aktivitas</span>
|
||||
</a>
|
||||
@endif
|
||||
|
||||
@if(auth()->user()->isPgAdmin() || auth()->user()->isAdmin())
|
||||
@@ -303,6 +309,11 @@
|
||||
<i class="fa-solid fa-clipboard-list w-5 text-center"></i>
|
||||
<span>Log Aktivitas Kendaraan</span>
|
||||
</a>
|
||||
|
||||
<a href="{{ route('qma.activity.summary') }}" class="flex items-center space-x-3 px-3 py-2.5 rounded-xl text-sm {{ request()->routeIs('qma.activity.summary') ? 'sidebar-item-active' : 'sidebar-item-inactive' }}">
|
||||
<i class="fa-solid fa-chart-pie w-5 text-center"></i>
|
||||
<span>Summary Aktivitas</span>
|
||||
</a>
|
||||
@endif
|
||||
@if(auth()->user()->isPgAdmin() || auth()->user()->isAdmin())
|
||||
<a href="{{ route('pg.guards.index') }}" class="flex items-center space-x-3 px-3 py-2.5 rounded-xl text-sm {{ request()->routeIs('pg.guards.*') ? 'sidebar-item-active' : 'sidebar-item-inactive' }}">
|
||||
@@ -365,6 +376,8 @@
|
||||
Data Kendaraan
|
||||
@elseif(request()->routeIs('qma.activity.log'))
|
||||
Log Aktivitas Kendaraan
|
||||
@elseif(request()->routeIs('qma.activity.summary'))
|
||||
Summary Aktivitas Kendaraan
|
||||
@elseif(request()->routeIs('profile.*'))
|
||||
Profil Saya
|
||||
@elseif(request()->routeIs('pg.gate.*'))
|
||||
|
||||
@@ -21,9 +21,10 @@
|
||||
</div>
|
||||
|
||||
<div class="flex items-center space-x-3 w-full sm:w-auto">
|
||||
<span class="inline-flex items-center px-4 py-2 rounded-xl text-xs font-bold bg-emerald-50 text-emerald-800 border border-emerald-200 shadow-sm">
|
||||
<i class="fa-solid fa-clipboard-check mr-2 text-emerald-600"></i> Total: {{ $activities->total() }} Catatan
|
||||
</span>
|
||||
<a href="{{ route('qma.activity.summary') }}" class="inline-flex items-center px-4 py-2.5 rounded-xl text-xs font-bold text-white bg-[#06213f] hover:bg-[#0b315b] shadow-sm transition group">
|
||||
<i class="fa-solid fa-chart-pie mr-2 text-emerald-400 group-hover:scale-110 transition-transform"></i>
|
||||
<span>Summary Aktifitas</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ Route::middleware('auth')->group(function () {
|
||||
Route::post('/vehicles/{id}', [VehicleController::class, 'update'])->name('vehicles.update');
|
||||
Route::delete('/vehicles/{id}', [VehicleController::class, 'destroy'])->name('vehicles.destroy');
|
||||
Route::get('/activity-log', [ActivityLogController::class, 'index'])->name('activity.log');
|
||||
Route::get('/activity-summary', [ActivityLogController::class, 'summary'])->name('activity.summary');
|
||||
});
|
||||
|
||||
// 4. Modul Private Guard (PG): Admin PG (Admin PG - AdminPG) & Pos Gerbang Satpam
|
||||
|
||||
Reference in New Issue
Block a user