@php
$formatIsk = fn($amount) => number_format((float) $amount, 0, ',', '.') . ' ISK';
$latestMonthTotal = $billing['month_groups'][0]['month_total'] ?? 0;
$averageMonthTotal = count($billing['month_groups']) > 0 ? (int) round($billing['grand_total'] / count($billing['month_groups'])) : 0;
$activeFilterCount = 0;
$monthsTracked = $stats->count();
$latestUniqueLocks = (int) ($stats->last()['count'] ?? 0);
$totalNewLocksInRange = (int) $stats->sum('new_locks');
$totalNewPropertiesInRange = (int) $stats->sum('new_properties');
$netGrowthRate = $latestUniqueLocks > 0 && $totalNewLocksInRange > 0
? round(($totalNewLocksInRange / max($latestUniqueLocks, 1)) * 100, 1)
: 0;
$billableMonths = count($billing['month_groups']);
$propertyGrowthRows = $stats
->flatMap(fn($row) => collect($row['properties'] ?? [])->map(fn($property) => [
'month' => $row['month'],
'name' => $property['name'],
'locks' => $property['locks'],
]))
->values();
$propertyCoverageRate = $monthsTracked > 0
? round(($propertyGrowthRows->count() / max($monthsTracked, 1)), 1)
: 0;
if (!empty($filters['from_month'])) $activeFilterCount++;
if (!empty($filters['to_month'])) $activeFilterCount++;
if (!empty($filters['property_id'])) $activeFilterCount++;
if (!empty($filters['property_name'])) $activeFilterCount++;
if (!empty($filters['only_billable'])) $activeFilterCount++;
if (count($selectedApis) !== count($apis)) $activeFilterCount++;
@endphp
{{-- ══════════════════ COMPACT HEADER ════════════════════════════════════ --}}
@include('superadmin.lock-statistics.partials.filters', ['pageRoute' => 'locks-by-month.analytics', 'showExports' => true])
{{-- 8 KPI cards --}}
Grand total billed
{{ $formatIsk($billing['grand_total']) }}
Latest month total
{{ $formatIsk($latestMonthTotal) }}
Average monthly total
{{ $formatIsk($averageMonthTotal) }}
Active filter groups
{{ $activeFilterCount }}
Latest unique locks
{{ $latestUniqueLocks }}
New locks in range
{{ $totalNewLocksInRange }}
New properties in range
{{ $totalNewPropertiesInRange }}
Months tracked
{{ $monthsTracked }}
{{-- 3 insight cards --}}
{{ $netGrowthRate }}%
Net lock velocity
New locks in range vs. latest unique lock base.
{{ $propertyCoverageRate }}
Properties / month
Monthly onboarding consistency in current filters.
{{ $billableMonths }}
Billable months
Grand: {{ $formatIsk($billing['grand_total']) }}
Avg: {{ $formatIsk($averageMonthTotal) }}
Verify billing continuity across the selected range.
{{-- Lock growth chart + table --}}
| Month |
Unique Locks |
New Locks |
New Properties |
@forelse($stats as $statRow)
| {{ $statRow['month'] }} |
{{ $statRow['count'] }} |
{{ $statRow['new_locks'] }} |
{{ $statRow['new_properties'] }} |
@empty
| No rows for selected filters. |
@endforelse
{{-- Property growth chart + table --}}
| Month |
Property Added |
Locks Added |
@forelse($propertyGrowthRows as $propertyRow)
| {{ $propertyRow['month'] }} |
{{ strip_tags((string) $propertyRow['name']) }} |
{{ $propertyRow['locks'] }} |
@empty
| No new properties in the selected range. |
@endforelse
@endsection
@push('css')
@endpush
@push('js')
@endpush