@extends('layouts.admin') @section('title', 'Reports & Analytics') @section('content')

Reports & Analytics

Tax Collection
Revenue Overview
HS Code Analysis
Product Analysis
Country Analysis
Import Origins
Custom Reports
Generate Report
Quick Statistics

{{ number_format(\App\Models\CalculationLog::count()) }}

Total Calculations

KES {{ number_format(\App\Models\CalculationLog::sum('total_payable'), 2) }}

Total Revenue

{{ number_format(\App\Models\HsCode::count()) }}

HS Codes

{{ number_format(\App\Models\Country::count()) }}

Countries

Recent Calculations
@php $recentCalculations = \App\Models\CalculationLog::with('user') ->latest() ->take(5) ->get(); @endphp @if($recentCalculations->count() > 0)
@foreach($recentCalculations as $calculation)
HS: @php // Handle both array and JSON string input if (is_array($calculation->input)) { $hsCode = $calculation->input['hs_code'] ?? 'N/A'; } else { $inputData = json_decode($calculation->input, true); $hsCode = $inputData['hs_code'] ?? 'N/A'; } @endphp {{ $hsCode }}
{{ $calculation->created_at->diffForHumans() }}
KES {{ number_format($calculation->total_payable, 2) }}
@endforeach
@else

No calculations found.

@endif
Popular HS Codes
@php $popularHsCodes = \App\Models\CalculationLog::selectRaw(' CASE WHEN JSON_VALID(input) THEN JSON_UNQUOTE(JSON_EXTRACT(input, "$.hs_code")) ELSE NULL END as hs_code, COUNT(*) as count ') ->whereNotNull('input') ->groupBy('hs_code') ->orderByDesc('count') ->take(5) ->get(); @endphp @if($popularHsCodes->count() > 0)
@foreach($popularHsCodes as $item) @if($item->hs_code) @php $hsCode = \App\Models\HsCode::where('hs_code', $item->hs_code)->first(); @endphp
{{ $item->hs_code }}
{{ $hsCode->description ?? 'Unknown' }}
{{ $item->count }} calculations
@endif @endforeach
@else

No HS code data available.

@endif
@endsection